### 循环性能对比
2019-11-10 本文已影响0人
君林_6183
let index = 0;
let arr = [];
while (index < 100000) {
arr.push(index);
index++;
}
console.time('one');
for (let i = 0; i < arr.length; i++) {
// arr[i]
}
console.timeEnd('one');
// one: 2.09765625ms
console.time('two');
for (let i = 0, len = arr.length; i < len; i++) {
// arr[i]
}
console.timeEnd('two');
// two: 0.839111328125ms
console.time('three');
for (let i = 0, item; item = arr[i++];) {
// console.log(arr[i])
}
console.timeEnd('three');
// three: 0.004150390625ms