jquery/lodash map vs for loop for json

JavaScript performance comparison

Revision 3 of this test case created by tomByrer

Info

v2 swapped Lo-Dash for Underscore, .each for .map, v3 updated libs to "current branch" versions.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/lodash/2/lodash.underscore.min.js"</script>

<script>
var array = [{"ID":1},{"ID":2},{"ID":3},{"ID":4},{"ID":5},{"ID":6},{"ID":7},{"ID":8},{"ID":9},{"ID":11},{"ID":12},{"ID":13},{"ID":14},{"ID":15},{"ID":16},{"ID":17},{"ID":18},{"ID":19},{"ID":21},{"ID":22},{"ID":23},{"ID":24},{"ID":25},{"ID":26},{"ID":27},{"ID":28},{"ID":29},{"ID":31},{"ID":32},{"ID":33},{"ID":34},{"ID":35},{"ID":36},{"ID":37},{"ID":38},{"ID":39},{"ID":41},{"ID":42},{"ID":43},{"ID":44},{"ID":45},{"ID":46},{"ID":47},{"ID":48},{"ID":49},{"ID":51},{"ID":52},{"ID":53},{"ID":54},{"ID":55},{"ID":56},{"ID":57},{"ID":58},{"ID":59},{"ID":61},{"ID":62},{"ID":63},{"ID":64},{"ID":65},{"ID":66},{"ID":67},{"ID":68},{"ID":69},{"ID":71},{"ID":72},{"ID":73},{"ID":74},{"ID":75},{"ID":76},{"ID":77},{"ID":78},{"ID":79},{"ID":81},{"ID":82},{"ID":83},{"ID":84},{"ID":85},{"ID":86},{"ID":87},{"ID":88},{"ID":89},{"ID":91},{"ID":92},{"ID":93},{"ID":94},{"ID":95},{"ID":96},{"ID":97},{"ID":98},{"ID":99},{"ID":100}];
</script>
<script>
Benchmark.prototype.setup = function() {
    var $ = window.$;
    var _ = window._;
   
    var e=[];
    var array = window.array;
};
</script>

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'
e = $.map(array, function(index, element) { return element.toString() +Math.random(); })
pending…
_.map
e = _.map(array, function(element, index) { return element.toString() +Math.random(); }); //Lo-Dash
pending…
for
var l = array.length;
for (var i=0;i<l; i++) {
  e[i] = array[i].toString() + Math.random();
}
pending…
forEach
array.forEach(function(element, index){ e[index] = element.toString() + Math.random();})
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