Test lodash foreach vs native

JavaScript performance comparison

Test case created by Jeroen Valcke

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>

      
<script>
Benchmark.prototype.setup = function() {
           
    var length = 10000;
    var array = [];
    array.length = length;
    
    for (var i = 0; i < length; i++) {
      array[i] = i;
    }

};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Lodash foreach
var list = [];

_.forEach(array, function(d) {
  list.push(d);
});
pending…
Native map
var list = array.map(function(d) {
   return d;
});
pending…
Native foreach
var list = [];

array.forEach(function(d) {
   list.push(d);
});
pending…
Lodash map
var list = _.map(array, function(d) {
  return d;
});
pending…

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

0 Comments