for-each vs for js

Benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

Benchmark.prototype.setup = function() {
    var array = new Array(), 
    i = 0;
    
    for (i; i < 1000; i++)
    array.push(i);
    
    var len = array.length;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
for-each
array.forEach(function(value, idx){
 console.log(value);
});
ready
while
for (var i=0; i < len; i++) {
console.log(array[i]);
}
ready
jQuery-each
$.each(array, function(idx, value){
console.log(value);
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.