Profiling Test
by colintoh
HTML
Open up your browser's developer console to see the result.
JavaScript
var arr = [];
for(var i = 0; i < 10000000; i++) {
arr[i]=i;
}
// Using the native forEach
console.time("forEach");
arr.forEach(function(v){
v;
});
console.timeEnd("forEach");
// Using for loop
console.time("for loop");
for(var j = 0; j < arr.length; j++){
arr[j];
}
console.timeEnd("for loop");
//Using for loop with cache
console.time("for loop with cache");
for(var j = 0, l = arr.length; j < l; j++){
arr[j];
}
console.timeEnd("for loop with cache");
//Using while loop
console.time("while");
var h = 0;
while (h < arr.length) {
arr[h++];
};
console.timeEnd("while")