lodash vs. for

JavaScript performance comparison

Test case created

Preparation code

<script src="//raw.github.com/bestiejs/lodash/v1.3.1/dist/lodash.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var arr = [];
    for (var i = 0; i < 1e4; ++i) {
      arr[i] = Math.random() * 1e4;
    }
   
    var total = 0;
    function sum(x) {
      total += x;
    }
   
    function forEach(arr, fn) {
        for (var i = 0, l = arr.length; i < l; ++i) {
          fn(arr[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
_(arr).forEach(sum);
pending…
for
forEach(arr, sum);
pending…

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

Compare results of other browsers

0 comments

Add a comment