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
Just curious about performance of getters / setters vs classic properties.
<script>
var Point1 = function(x, y) {
this._x = x;
this._y = y;
};
Object.defineProperties(Point1.prototype, {
x: {
get: function() {
return this._x;
},
set: function(v) {
this._x = v;
},
enumerable: true
},
y: {
get: function() {
return this._y;
},
set: function(v) {
this._y = v;
},
enumerable: true
},
_x: {
value: 0
},
_y: {
value: 0
}
});
var Point2 = function(x, y) {
this.x = x;
this.y = y;
}
var Point3 = function(x, y) {
this.x = x;
this.y = y;
this.getX = function() {
return this.x;
}
this.setX = function(x) {
this.x = x;
}
this.getY = function() {
return this.y;
}
this.setY = function(y) {
this.y = y;
}
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
getters / setters |
| ready |
properties |
| ready |
custom getters / setters |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.