native vs. underscore vs lo-dash

JavaScript performance comparison

Revision 11 of this test case created

Info

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

Preparation code

<script>
  var lodashVersion = '1.3.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.1/underscore-min.js';
  lodash.src = 'http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js';
  document.body.appendChild(underscore);
  document.body.appendChild(lodash);
</script>
<script>
Benchmark.prototype.setup = function() {
    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
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
native
arr.map(function(num) {
  return num + num;
});
pending…
underscore
underscore.map(arr, function(num) {
  return num + num;
});
pending…
underscore (wrapped)
var arr = underscore(arr);

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

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment