native vs. underscore vs lo-dash (v16)

Revision 16 of this benchmark created on


Description

This test compares the performance of a native array vs. underscore vs lo-dash

Preparation HTML

<script>
  var lodashVersion = '2.4.1';
  function noConflict () {
    var isLodash = (_.VERSION === lodashVersion);
    if (isLodash) {
      window.lodash = _.noConflict();
    } else {
      window.underscore = _.noConflict();
    }
  }

  var underscore = document.createElement('script');
  var lodash = document.createElement('script');
  underscore.onload = noConflict;
  lodash.onload = noConflict;
  underscore.src = 'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js';
  lodash.src = 'http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js';
  document.body.appendChild(underscore);
  document.body.appendChild(lodash);
</script>

Setup

var arr = Array.apply(null, Array(10000)).map(function(el,i){return i})
    
    var wrappedWhile = function(arr, func){
        var i=-1,
            len = arr.length,
            res = []
        while(i++ < len){
            res[i] = func(arr[i])
        }
        return res
    }
    
    var sum = function(num){
        return num+num
    }
    var i=-1,
        len = arr.length,
        res = [],
        num

Test runner

Ready to run.

Testing in
TestOps/sec
native
arr.map(function(num) {
  return num + num;
});
ready
underscore
underscore.map(arr, function(num) {
  return num + num;
});
ready
underscore (wrapped)
var arr = underscore(arr);

arr.map(function(num) {
  return num + num;
});
ready
lo-dash
lodash.map(arr, function(num) {
  return num + num;
});
ready
while
var i=-1,
    len = arr.length,
    res = new Array(len),
    num
while(i++ < len){
    num = arr[i]
    res[i] = num+num
}
ready
while 2
while(i++ < len){
    num = arr[i]
    res[i] = num+num
}
ready
wrapped while
wrappedWhile(arr, sum)
ready

Revisions

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