wqfwewefewrw

JavaScript performance comparison

Revision 20 of this test case created

Preparation code

<script src="https://rawgithub.com/petkaantonov/bluebird/master/js/bluebird.js">
</script>
<script src="https://rawgithub.com/kriskowal/q/master/q.min.js"></script>

<script src="https://rawgithub.com/rkatic/p/master/p.min.js"></script>

    <script>
        define = function( factory ) {
            when = factory();
        };
        define.amd = {};
    </script>
<script>!function(n,t){"use strict";n(function(){n.defer=i;n.resolve=r;n.reject=u;n.join=d;n.all=v;n.map=j;n.reduce=w;n.settle=m;n.any=y;n.some=p;n.isPromise=l;n.promise=o;function n(n,t,e,u){return r(n).then(t,e,u)}function e(n,t){this.then=n;this.inspect=t}e.prototype={otherwise:function(n){return this.then(z,n)},ensure:function(n){return this.then(t,t).yield(this);function t(){return r(n())}},yield:function(n){return this.then(function(){return n})},spread:function(n){return this.then(function(t){return v(t,function(t){return n.apply(z,t)})})},always:function(n,t){return this.then(n,n,t)}};function r(n){return o(function(t){t(n)})}function u(t){return n(t,s)}function i(){var n,t,e;n={promise:z,resolve:z,reject:z,notify:z,resolver:{resolve:z,reject:z,notify:z}};n.promise=t=o(u);return n;function u(u,i,o){n.resolve=n.resolver.resolve=function(n){if(e){return r(n)}e=true;u(n);return t};n.reject=n.resolver.reject=function(n){if(e){return r(s(n))}e=true;i(n);return t};n.notify=n.resolver.notify=function(n){o(n);return n}}}function o(n){var t,r=[];try{n(l,p,y)}catch(u){p(u)}return new e(i,c);function i(n,e,u){return o(function(i,o,f){r?r.push(function(t){t.then(n,e,u).then(i,o,f)}):A(function(){t.then(n,e,u).then(i,o,f)})})}function c(){return t?t.inspect():T()}function l(n){if(!r){return}t=f(n);h(r,t);r=z}function p(n){l(s(n))}function y(n){if(r){h(r,a(n))}}}function f(n){if(n instanceof e){return n}if(!(n===Object(n)&&"then"in n)){return c(n)}return o(function(t,e,r){A(function(){try{var u=n.then;if(typeof u==="function"){I(u,n,t,e,r)}else{t(c(n))}}catch(i){e(i)}})})}function c(n){var t=new e(function(e){try{return typeof e=="function"?f(e(n)):t}catch(r){return s(r)}},function(){return b(n)});return t}function s(n){var t=new e(function(e,r){try{return typeof r=="function"?f(r(n)):t}catch(u){return s(u)}},function(){return x(n)});return t}function a(n){var t=new e(function(e,r,u){try{return typeof u=="function"?a(u(n)):t}catch(i){return a(i)}});return t}function h(n,t){A(function(){var e,r=0;while(e=n[r++]){e(t)}})}function l(n){return n&&typeof n.then==="function"}function p(t,e,r,u,i){return n(t,function(t){return o(f).then(r,u,i);function f(r,u,i){var o,f,c,s,a,h,l,p;l=t.length>>>0;o=Math.max(0,Math.min(e,l));c=[];f=l-o+1;s=[];if(!o){r(c)}else{h=function(n){s.push(n);if(!--f){a=h=D;u(s)}};a=function(n){c.push(n);if(!--o){a=h=D;r(c)}};for(p=0;p<l;++p){if(p in t){n(t[p],v,y,i)}}}function y(n){h(n)}function v(n){a(n)}}})}function y(n,t,e,r){function u(n){return t?t(n[0]):n[0]}return p(n,1,u,e,r)}function v(n,t,e,r){return g(n,D).then(t,e,r)}function d(){return g(arguments,D)}function m(n){return g(n,b,x)}function j(n,t){return g(n,t)}function g(t,e,r){return n(t,function(t){return o(u);function u(u,i,o){var f,c,s,a,h;s=c=t.length>>>0;f=[];if(!s){u(f);return}a=function(t,c){n(t,e,r).then(function(n){f[c]=n;if(!--s){u(f)}},i,o)};for(h=0;h<c;h++){if(h in t){a(t[h],h)}else{--s}}}})}function w(t,e){var r=I(O,arguments,1);return n(t,function(t){var u;u=t.length;r[0]=function(t,r,i){return n(t,function(t){return n(r,function(n){return e(t,n,i,u)})})};return k.apply(t,r)})}function b(n){return{state:"fulfilled",value:n}}function x(n){return{state:"rejected",reason:n}}function T(){return{state:"pending"}}var k,O,I,M,E,F,L,P,q,z;E=[];function A(n){if(E.push(n)===1){B()}}function B(){M(C)}function C(){var n,t=0;while(n=E[t++]){n()}E=[]}F=t.setTimeout;M=typeof setImmediate==="function"?setImmediate.bind(t):typeof process==="object"&&process.nextTick?process.nextTick:typeof vertx==="object"?vertx.runOnLoop:function(n){F(n,0)};L=Function.prototype;P=L.call;I=L.bind?P.bind(P):function(n,t){return n.apply(t,O.call(arguments,2))};q=[];O=q.slice;k=q.reduce||function(n){var t,e,r,u,i;i=0;t=Object(this);u=t.length>>>0;e=arguments;if(e.length<=1){for(;;){if(i in t){r=t[i++];break}if(++i>=u){throw new TypeError}}}else{r=e[1]}for(;i<u;++i){if(i in t){r=n(r,t[i],i,t)}}return r};function D(n){return n}return n})}(typeof define==="function"&&define.amd?define:function(n){module.exports=n()},this);</script>

 
<script>
Benchmark.prototype.setup = function() {
    function addOne(x) {
        return x + 1;
    }
   
    Q.longStackJumpLimit = 0;
};

Benchmark.prototype.teardown = function() {
    console.log(d);
};
</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
var d = Q.defer();
d.promise.then(addOne);
d.resolve(1);
pending…
when
var d = when.defer();
d.promise.then(addOne);
d.resolve(1);
pending…
P
var d = P.defer();
d.promise.then(addOne);
d.resolve(1);
pending…
Bluebird
var d = Promise.pending();
d.promise.then(addOne);
d.fulfill(1);
pending…
Callback
function callback(value, cb) {
   cb(value)
}
callback(1, addOne);
 
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