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
//prototype
var AnimalA = function(name) {
this.name = name;
this.nick = null;
};
AnimalA.prototype.speak = function() {
alert(this.name + ' spoke');
};
AnimalA.prototype.setNick = function(a) {
this.nick = a;
};
AnimalA.prototype.getNick = function() {
alert(this.nick);
};
//closures
var AnimalB = function(petName) {
var nick = null;
return {
name: petName,
speak: function() {
alert(this.name + ' spoke');
},
setNick: function(a) {
nick = a;
},
getNick: function() {
alert(nick);
}
};
};
//Objects
var AnimalC = function(name) {
this.name = name;
var nick = null;
this.speak = function() {
alert(this.name + ' spoke');
};
this.setNick = function(a) {
nick = a;
};
this.getNick = function() {
alert(nick);
};
};
//Object literals
var AnimalD = {
name: name,
nick: null,
setName: function(petName) {
this.name = petName;
},
speak: function() {
alert(this.name + ' spoke');
},
setNick: function(a) {
this.nick = a;
},
getNick: function() {
alert(this.nick);
}
};
var clone = (function() {
function Clone() {}
return function(obj) {
Clone.prototype = obj;
return new Clone();
};
}());
Ready to run.
Test | Ops/sec | |
---|---|---|
prototype |
| ready |
closures |
| ready |
objects |
| ready |
object literals |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.