Lodash forEach vs for

JavaScript performance comparison

Test case created

Preparation code

<script src="//raw.github.com/bestiejs/lodash/v1.1.1/dist/lodash.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    var a = {};
    var newObj = {};
   
    for (var i = 0; i < 1000; i++)
    a['' + i] = i;
};
</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
lodash forEach
_.forEach(a, function(key, val) {
  newObj[key] = val;
});
pending…
for each
for (var i in a)
newObj[i] = a;
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