angular $q vs bluebird (v14)

Revision 14 of this benchmark created by ys on


Description

Simple comparison of promise creation and resolution between Angular's $q, bluebird, and native ES6 Promise (only in Chrome and FF).

Preparation HTML

!function(){var t;return t=function(){function t(t){this._value=null,t(f(this,r),f(this,u))}var n,e,o,u,r,i,f,c,a,l;return t.prototype.then=function(n,e){var o,u;return u=this,o=this._hCount+4,this[o]=new t(function(t,o){return i(u,n,e,t,o)})},t.prototype["catch"]=function(t){return this.then(void 0,t)},t.resolve=function(n){return new t(function(t,e){l(n,t,e)})},t.reject=function(n){return new t(function(t,e){e(n)})},t.race=function(n){return new t(function(t,e){var o,u,r;for(o=0,u=n.length;u>o;o++)r=n[o],l(r,t,e)})},t.all=function(n){return new t(function(t,e){var o,u,r,i,f,c,a;for(c=[],o=n.length,r=function(n){l(a,function(e){return c[n]=e,0===--o?t(c):void 0},e)},u=i=0,f=n.length;f>i;u=++i)a=n[u],r(u)})},r=0,u=1,o=2,e=5,n="circular promise resolution chain",t.prototype._state=o,t.prototype._value=null,t.prototype._hCount=0,c=function(){return"undefined"!=typeof process&&null!==process&&process.nextTick?process.nextTick:"undefined"!=typeof setImmediate&&null!==setImmediate?setImmediate:function(t){return t()}}(),i=function(t,n,u,r,i){var f;f=t._hCount,t[f]=n,t[f+1]=u,t[f+2]=r,t[f+3]=i,t._hCount+=e,t._state!==o&&a(t,f)},l=function(t,n,e){var o,u,r,i;if(r=typeof t,null===t||"function"!==r&&"object"!==r)n&&n(t);else{try{i=t.then}catch(f){return o=f,void e(o)}if("function"==typeof i)try{u=!1,i.call(t,function(t){return u?void 0:(u=!0,l(t,n,e))},function(t){return u?void 0:(u=!0,e(t))})}catch(f){o=f,u||e(o)}else n(t)}},a=function(t,e){return c(function(){var o,u,r,i;if(u=t[e+t._state],"function"==typeof u){try{i=u(t._value)}catch(f){return o=f,void t[e+3](o)}if(i===t[e+4])return"function"==typeof i[r=e+1]?i[r](new TypeError(n)):void 0;l(i,t[e+2],t[e+3])}else t[e+2+t._state](t._value)})},f=function(t,n){return function(u){var r;if(t._state===o)for(t._state=n,t._value=u,r=0;r<t._hCount;)a(t,r),r+=e}},"object"==typeof module&&"object"==typeof module.exports?module.exports=t:"function"==typeof define&&define.amd?define(function(){return t}):"undefined"!=typeof window&&null!==window&&(window.Yaku=t),t}()}();

Test runner

Ready to run.

Testing in
TestOps/sec
Yaku Promise instantiate and resolve
// async test
var p = new Yaku(function(resolve, reject) {
  resolve('foo');
}).
then(function() {
  deferred.resolve()
});
ready
bluebird instantiate and resolve
// async test
var p = new Promise(function(resolve, reject) {
  resolve('foo');
}).
then(function() {
  deferred.resolve()
});
ready
Native
// async test
var p = new NativePromise(function(resolve, reject) {
  resolve('foo');
}).
then(function() {
  deferred.resolve()
});
ready

Revisions

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