underscore / lodash

JavaScript performance comparison

Revision 16 of this test case created


no one uses forEach to map over array to create another array using push especially when you use a functional library like underscore or lodash so this was a benchmark of completely useless use of those libraries. if you create one array that has (possibly transformed) values from another array then you should use map. i updated the tests to more reasonable way of making one array from elements of another one by applying some function (in this case a function that returns the same value unchanged - like in the original tests so the results are the same).

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js">
  var underscore = _.noConflict();
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.min.js">
  var lodash = _.noConflict();
<script src='//rawgithub.com/dtao/lazy.js/master/lazy.js'></script>
Benchmark.prototype.setup = function() {
    var lodash = window.lodash,
        underscore = window.underscore,
        Lazy = window.Lazy;
    var r,
        array = [];
    for (var i = 0; i < 20; i++) {
      array[i] = i;

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
map underscore
r = underscore.map(array, function(v) { return v; });
map lodash
r = lodash.map(array, function(v) { return v; });
map Lazy.js
r = Lazy(array).map(function(v) { return v; });
map native
r = array.map(function(v) { return v; });
for loop
r = [];
for (var i=0; i<array.length; i++) { r[i] = array[i]; }

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment