foreach - jQuery vs LoDash vs Native (v8)

Revision 8 of this benchmark created on


Preparation HTML

<div id="content">
<ul class="products">
</ul>
</div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.0/lodash.min.js"></script>

Setup

var $content = $('#content').hide(),
    $products = $content.find('.products'),
    str = '';
    i = 0,
    arr = [];
    
    for (var k = 0, max = 1000 ; i < max; i += 1) {
          arr.push({'name': 'test'});
        }
    
    var len = arr.length;

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery
$.each(arr, function(index, product) {
str += '<li>' + product.name + '</li>';
});
$products.append(str);
ready
LoDash
_.each(arr, function(product) {
str += '<li>' + product.name + '</li>';
});
$products.append(str);
ready
Native
for (var i = 0; i < len; i += 1) {
                str += '<li>' + arr[i].name + '</li>';
}
$products.append(str);
ready

Revisions

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