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

Revision 46 of this benchmark created by _.map vs. loop on


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>

Setup

var arr = new Array(1e3);
    for (var i = 0; i < arr.length; ++i) {
      arr[i] = Math.floor(Math.random() * 1e3);
    }
    
    function sum(s, x) {
      return s + x;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
native loop/push
var r = 0;
for (var i = 0, l = arr.length; i < l; i++) {
  r += arr[i];
}
ready
array map
var r = arr.reduce(sum, 0);
ready
underscore
var r = underscore.reduce(arr, sum, 0);
ready
lo-dash
var r = lodash.reduce(arr, sum, 0);
ready

Revisions

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