Paroles

JavaScript performance comparison

Revision 13 of this test case created by Raymond

Info

Compare some Promise/A implementation.

Same test as rev 10, but with setImmediate shim removed to see what libraries do on their own.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://rawgithub.com/kriskowal/q/master/q.js"></script>
<script src="https://rawgithub.com/rkatic/p/master/p.js"></script>
    <script>
        define = function( factory ) {
            when = factory();
        };
        define.amd = {};
    </script>
<script src="https://rawgithub.com/cujojs/when/master/when.js"></script>
<script src="https://rawgithub.com/JeanHuguesRobert/l8/master/lib/whisper.js"></script>

 
<script>
Benchmark.prototype.setup = function() {
    function addOne(x) {
        return x + 1;
    }
    // For whatever reason, Q is undefined under Internet Explorer...
    if( typeof Q !== "undefined" ){
      Q.longStackJumpLimit = 0;
    }
    // Worse... none of the global variables (Q, when, P, Parole) is available... is jsperf broken?
   
};
</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
Q
// async test
var d = Q.defer();
d.promise.then(addOne)
.then( function(){ deferred.resolve() } );
d.resolve(1);
pending…
when
// async test
var d = when.defer();
d.promise.then(addOne)
.then( function(){ deferred.resolve() } );
d.resolve(1);
pending…
P
// async test
var d = P.defer();
d.promise.then(addOne)
.then( function(){ deferred.resolve() } );
d.resolve(1);
pending…
Parole
// async test
var p = Parole();
p.then( addOne )
.then( function(){ deferred.resolve() } );
p( null, 1 );
pending…
Parole bis
// async test
var p = Parole();
p.then( addOne )
.then( function(){ deferred.resolve() } );
p.resolve( 1 );
pending…
Parole Q
// async test
var p = Parole.Q.defer();
p.promise.then( addOne )
.then( function(){ deferred.resolve() } );
p.resolve( 1 );
pending…
jQuery
// async test
var p = new $.Deferred();
p.then(addOne)
.then( function(){ deferred.resolve() });
p.resolve( 1 );
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