p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Consolas; color: #6b82d9 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Consolas; color: #596972 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Consolas; min-height: 22.0px }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Consolas; color: #b58a00 }
span.s1 { color: #d8a100 }
span.s2 { color: #596972 }
span.s3 { color: #6b82d9 }
span.s4 { color: #97a700 }
span.s5 { color: #ad5cff }
span.s6 { color: #3c7400 }
function a() {
var arr = new Array(1000000);
for(var i = 0; i < arr.length;i ++) {
arr[i] = i;
}
var start1 = new Date().getTime();
for(var i = 0; i < arr.length;i ++) {
arr[i] = i+1;
}
var stop1 = new Date().getTime();
console.info(stop1-start1);
var start2 = new Date().getTime();
arr.forEach(function(value,index,array) {
arr[i] = i+1;
});
var stop2 = new Date().getTime();
console.info(stop2-start2);
var start3 = new Date().getTime();
arr.map(function(index,value,array) {
arr[i] = i+1;
});
var stop3 = new Date().getTime();
console.info(stop3-start3);
}
a();
>>>4
>>>29
>>>155
原文地址:https://www.cnblogs.com/Alice-Xu/p/8807450.html