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
Testing various techniques for creating getters / setters in JavaScript.
<script>
var _tmp = 0;
var obj = {
prop: 0
}
var obj1 = {
_prop: 0,
getProp: function() {
return this._prop;
},
setProp: function(value) {
this._prop = value;
}
};
var obj2 = {
_prop: 0,
get prop() {
return this._prop;
},
set prop(value) {
this._prop = value;
},
};
var obj3 = {
_prop: 0
}
Object.defineProperty(obj3, "prop", {
get: function() {
return this._prop;
},
set: function(val) {
this._prop = val;
}
});
var obj4 = {
_prop: 0
}
obj4.__defineGetter__("prop", function() {
return this._prop;
});
obj4.__defineSetter__("prop", function(val) {
this._prop = val;
});
class c5 {
_prop;
constructor() {
this._prop = 0;
}
get prop() {
return this._prop;
}
set prop(value) {
this._prop = value;
}
}
obj5 = new c5();
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Methods |
| ready |
get / set |
| ready |
Object.defineProperty |
| ready |
__defineGetter__ |
| ready |
Property |
| ready |
Methods #2 getter only |
| ready |
get / set #2 getter only |
| ready |
Object.defineProperty #2 getter only |
| ready |
__defineGetter__ #2 getter only |
| ready |
Property #2 getter only |
| ready |
Class get / set |
| ready |
Class getter only |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.