小编MHz*_*ode的帖子

node.js拼接速度太慢,超过70000个项目

我是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)

arrays v8 node.js

6
推荐指数
1
解决办法
299
查看次数

标签 统计

arrays ×1

node.js ×1

v8 ×1