Lodash foreach (v25)

Revision 25 of this benchmark created on


Description

Added native js forEach to the comparisons plus from version 6 added passing the value from array to each test in order to make the test more meaningful all around.

Added simple ForEach function for demonstration.

Added Lazy.js, Zepto and minimal.js in version 8

Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.min.js"></script>
<script src="http://code.jquery.com/jquery-git2.js"></script>
<script src="https://rawgithub.com/timmywil/minimal/master/src/minimal.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script>

Setup

var array = ["one", "two", "three", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
    
    var cb = function(item){};
    
    // For comparison
    function ForEach(array, cb) {
        var i = 0, len = array.length;
        for (i; i < len; i++) {
            cb(array[i]);
        }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery .each()
$(array).each(cb);
ready
Lo-dash _.each()
_.each(array, cb);
ready
standard for loop
for (var i = 0; i < array.length; i++) {
    cb(array[i]);
}
ready
optimised for loop
for (var i = 0, len = array.length; i < len; i++) {
    cb(array[i]);
}
ready
optimised 2 for loop
var i = 0, len = array.length;
for (i; i < len; i++) {
    cb(array[i]);
}
ready
while--
var len = array.length;
while(len--) {
    cb(array[len]);
}
ready
array.forEach
array.forEach(cb)
ready
[].forEach.call()
[].forEach.call(array, cb)
ready
ForEach
ForEach(array, cb);
 
ready
Zepto.each
Zepto.each(array, cb);
 
ready
minimal.each
minimal.each(array, cb);
ready
for in
for (var i in array) {
    cb(i);
}
ready

Revisions

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