Looping in Javascript (v62)

Revision 62 of this benchmark created by Adam Kendall 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="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js">
</script>
<script>
var underscore = _.noConflict();
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js">
</script>
<script>
var lodash = _.noConflict();
</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
underscore.each
underscore.each(arr, function(idx, val) {
    // Do nothing.
});
ready
forEach
arr.forEach(function(val, idx) {
    // Do nothing.
})
ready
lodash.each
lodash.each(arr, function(idx, val) {
    // Do nothing.
});
ready

Revisions

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