我是node.js的新手.
我试图将70000个项目插入数组,然后删除所有项目:
var Stopwatch = require("node-stopwatch").Stopwatch;
var stopwatch = Stopwatch.create();
var a = []
stopwatch.start();
for (var i = 1 ; i < 70000 ; i++){
a.push((parseInt(Math.random() * 10000)) + "test");
}
for (var i = 1 ; i < 70000 ; i++){
a.splice(0,1);
}
stopwatch.stop();
console.log("End: " + stopwatch.elapsedMilliseconds + " : " + a.length);Run Code Online (Sandbox Code Playgroud)
它工作正常,输出是:
PS C:\Users\Documents\VSCode> node test.js
End: 51 : 0
Run Code Online (Sandbox Code Playgroud)
但是当我将项目数增加到72000时,结束需要太多时间:
var Stopwatch = require("node-stopwatch").Stopwatch;
var stopwatch = Stopwatch.create();
var a = []
stopwatch.start();
for …Run Code Online (Sandbox Code Playgroud)