var SIZE = 1000000;
function createObject(value){
this.tag = "i" + value;
this.value = value;
}
function createObject2(tag, value){
this.tag = tag;
this.value = value;
}
var items = new Array(SIZE);
var time0 = new Date().getTime();
for(var i = 0; i < SIZE; i++){
var cell = createObject(i);
items[i] = cell;
}
var time1 = new Date().getTime();
console.log("time0-1: " + (time1 - time0));
for(var i = 0; i < SIZE; i++){
var cell = {};
cell.tag = "i" + i;
cell.value = i;
items[i] = cell;
}
var time2 = new Date().getTime();
console.log("time1-2: " + (time2 - time1));
for(var i = 0; i < SIZE; i++){
var cell = new Object();
cell.tag = "i" + i;
cell.value = i;
items[i] = cell;
}
var time3 = new Date().getTime();
console.log("time2-3: " + (time3 - time2));
for(var i = 0; i < SIZE; i++){
items[i] = createObject("i" + i, i);
}
var time4 = new Date().getTime();
console.log("time3-4: " + (time4 - time3));
我需要创建100万个对象,不知道有什么更快的方法,SpreadJS如何解决的。 因为我发现创建100万个对象,就要12秒左右。有什么好办法? |