Looping in Javascript (v60)

Revision 60 of this benchmark created on


Description

Testing different types of loops in javascript, assuming you need a reference to each variable.

Preparation HTML

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

Setup

arr = [{'a':1},{'a':1},{'a':1},{'a':1},{'a':1},{'a':1},{'a':1},{'a':1},{'a':1},{'a':1},{'a':1},{'a':1}];

Test runner

Ready to run.

Testing in
TestOps/sec
JQuery
$.each(arr, function(idx, val) {
    // do nothing.
});
 
ready
for
for (var i = 0; i < arr.length; i += 1) {
    var val = arr[i];
    // Do nothing else.
}
ready
_.each
_.each(arr, function(idx, val) {
    // Do nothing.
});
ready
forEach
arr.forEach(function(val, idx) {
    // Do nothing.
})
ready

Revisions

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