native vs. map vs. underscore vs lo-dash vs jquery vs dojo vs zepto (v45)

Revision 45 of this benchmark created by DontShootMe on


Description

This test compares the performance of a naive array loop/push vs. array map vs. underscore vs lo-dash vs jquery.

revision 43 : added native negative while.

revision 45 : added native loop without push.

Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script>
var underscore = _.noConflict();
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script>
var lodash = _.noConflict();
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$.noConflict(false);
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.0/dojo/dojo.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/zepto/1.1.4/zepto.min.js"></script>

Setup

var arr = underscore.shuffle(underscore.range(50));
    var dojoArr = require("dojo/_base/array");

Test runner

Ready to run.

Testing in
TestOps/sec
native loop/push
var r = [],
  arrLen = arr.length,
  num;
for (var i = 0; i < arrLen; i++) {
  num = arr[i]
  r.push(num * num)
}
ready
native loop without push
var arrLen = arr.length,
  r = new Array(arrLen),
  num;
for (var i = 0; i < arrLen; i++) {
  num = arr[i];
  r[i] = num * num;
}
ready
array map
var r = arr.map(function(num) {
  return num * num;
});
ready
underscore
var r = underscore.map(arr, function(num) {
  return num * num;
});
ready
lo-dash
var r = lodash.map(arr, function(num) {
  return num * num;
});
ready
jQuery
var r = jQuery.map(arr, function(num) {
  return num * num;
});
ready
dojo array.map
var r = dojoArr.map(arr, function(num) {
  return num * num;
});
ready
zepto
var r = $.map(arr, function(num) {
  return num * num;
});
ready
native negative while
var i = arr.length,
  r = new Array(i),
  num;
while (i--) {
  num = arr[i];
  r[i] = num * num;
}
ready

Revisions

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