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
Test different access method to an object property.
<script>
obj = {
_x: 0
}
pobj = {
_x: 0
}
pobj.prototype = {};
funct = {
get: function() {
return this._x
},
set: function(value) {
this._x = value
}
}
Object.defineProperty(obj, "x", {
get: funct['get'],
set: funct['set']
})
Object.defineProperty(obj, "nx", {
get: funct['get'],
set: funct['set'],
configurable: true,
enumerable: true,
})
Object.defineProperty(pobj.prototype, "x", {
get: funct['get'],
set: funct['set']
})
Object.defineProperty(pobj.prototype, "nx", {
get: funct['get'],
set: funct['set'],
configurable: true,
enumerable: true
})
obj.__defineGetter__('y', funct['get']);
obj.__defineSetter__('y', funct['set']);
obj.prototype = {
get z() {
return this._x;
}, set z(value) {
this._x = value;
}
}
obj.setX = function(value) {
this._x = value;
}
function check() {
// sum of 1-1000
// if(console && console.assert) {
// console.assert(acc === 500500, 'acc should be 500500');
// }
}
</script>
obj._x = 0;
pobj._x = 0;
i = 1000;
Ready to run.
Test | Ops/sec | |
---|---|---|
Object.defineProperty |
| ready |
__defineGetter__ |
| ready |
Normal |
| ready |
Prototype |
| ready |
Setter |
| ready |
Object.defineProperty configurable |
| ready |
Object.defineProperty on proto |
| ready |
Object.defineProperty on proto, configurable, writable |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.