jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
A comparison of the two most highly performant promise implementations and the new native promises.
<script src="http://rsvpjs-builds.s3.amazonaws.com/rsvp-latest.js"></script>
<script src="https://rawgithub.com/petkaantonov/bluebird/master/js/browser/bluebird.js"></script>
<script>var BPromise = Promise.noConflict();
if ((Promise + "").indexOf("native") < 0) alert("not native promises");
</script>
<script>
(function(){
window.P = function(callback){
if (callback instanceof Deferred) {
this.deferred = callback
}
else {
var deferred = this.deferred = new Deferred()
callback(function(){
deferred.resolve.apply(deferred, arguments)
}, function(){
deferred.reject.apply(deferred, arguments)
})
}
}
Promise.prototype.done = function(){
this.deferred.done.apply(this.deferred, arguments)
return this
}
Promise.prototype.fail = function(){
this.deferred.fail.apply(this.deferred, arguments)
return this
}
Promise.prototype.then = function(done, fail){
return this.deferred.then.apply(this.deferred, arguments)
}
Promise.prototype.zen = function(done){
return this.then(function(){
var args = Array.prototype.slice.call(arguments)
return new Promise(function(resolve, reject){
done.apply(undefined, [resolve, reject].concat(args))
})
})
}
var Deferred = function(){
this.dones = []
this.fails = []
this.state = "pending"
}
Deferred.prototype.done = function(done){
if (this.state == "resolved") done.apply(undefined, this.args)
this.dones.push(done)
return this
}
Deferred.prototype.fail = function(fail){
if (this.state == "rejected") fail.apply(undefined, this.args)
this.fails.push(fail)
return this
}
Deferred.prototype.promise = function(){
return new Promise(this)
}
Deferred.prototype.bind = function(promise){
var deferred = this
if (promise && promise.done && promise.fail) {
promise.done(function(){
deferred.resolve.apply(deferred, arguments)
})
.fail(function(){
deferred.reject.apply(deferred, arguments)
})
}
else {
this.resolve.apply(this, arguments)
}
}
Deferred.prototype.then = function(done, fail){
var deferred = new Deferred()
this.done(function(){
var promise = done.apply(undefined, arguments)
deferred.bind(promise)
})
.fail(function(){
var promise = fail.apply(undefined, arguments)
deferred.bind(promise)
})
return deferred.promise()
}
Deferred.prototype.resolve = function(){
if (this.state != "pending") return
var args = this.args = arguments
this.state = "resolved"
this.dones.forEach(function(done){
done.apply(undefined, args)
})
}
Deferred.prototype.reject = function(){
if (this.state != "pending") return
var args = this.args = arguments
this.state = "rejected"
this.fails.forEach(function(fail){
fail.apply(undefined, args)
})
}
})()
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Bluebird deferred |
| ready |
RSVP deferred |
| ready |
Bluebird classic |
| ready |
RSVP classic |
| ready |
Native Promises |
| ready |
My Promise |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.