Benchmark
Result
Codes
Execute before every test
var arr = Array(1000000).fill(null);
var dosmth;
for
- Uncached length
for (let i = 0; i < arr.length; i++) {
dosmth = arr[i];
}
for
- Cached length
let len = arr.length;
for (let i = 0; i < len; i++) {
dosmth = arr[i];
}
for.. of
for (let val of arr) {
dosmth = val;
}
while
- Uncached length
let i = 0;
while(i < arr.length){
dosmth = arr[i];
++i;
}
while
- Cached length
let i = 0;
const len = arr.length;
while(i < len){
dosmth = arr[i];
++i;
}
forEach
arr.forEach(el=>(dosmth = el));
map
arr.map(el=>(dosmth = el));