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
Add the constructor call to the test to see how that affects performance, since a lot of constructors are called every time they are used versus once for every action.
<script>
function ClosureColor(name) {
// Have no choice but to add these methods to the instance
this.getName = function () {
return name;
};
this.setName = function (n) {
name = n;
};
}
function ClosureReturnColor(name) {
// Return object instead of attaching to Function
return {
getName: function () {
return name;
},
setName: function (n) {
name = n;
}
}
}
function PropertyColor(name) {
this._name = name;
this.getName = function () {
return this._name;
};
this.setName = function (n) {
this._name = n;
};
}
function PrototypeColor(name) {
this._name = name;
}
PrototypeColor.prototype.getName = function () {
return this._name;
};
PrototypeColor.prototype.setName = function (n) {
this._name = n;
};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Closure |
| ready |
Property |
| ready |
Prototype |
| ready |
Closure Return |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.