belt loops

JavaScript performance comparison

Revision 3 of this test case created by John Cockrell

Info

this title is just too clever by, like, half.

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.min.js"></script>
<script>
var lodash = _.noConflict();
</script>
<script src="http://sjhcockrell.s3.amazonaws.com/downloads/belt.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var a = {},
        b = {};
   
    for (var i = 0; i < 20; i+=1) {
        a[i] = i;
    }
   
    for (var i = 0; i < 1000; i+=1 ) {
       b[i] = i;
    }
   
    function MathIt(n) {
       return n % 2;
    }
   
};
</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
B.forOwn - b
B.forOwn(b, MathIt);
pending…
B.forEach - b
B.forEach(b, MathIt);
pending…
Underscore.forEach - b
_.forEach(b, MathIt);
pending…
lodash.forOwn - b
lodash.forOwn(b, MathIt);
pending…
jquery.each - b
// NOTE: this is not as safe as the functions above; this is just for comparison.

$.each(b, function(ix, v) { MathIt(v); });
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