Lodash forEach vs for

JavaScript performance comparison

Test case created

Preparation code

<script src="https://raw.github.com/bestiejs/lodash/v1.1.1/dist/lodash.min.js">
Benchmark.prototype.setup = function() {
    var a = {};
    var newObj = {};
    for (var i = 0; i < 1000; i++)
    a['' + i] = i;

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;
for each
for (var i in a)
newObj[i] = a;

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