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
var global = this;
(function () {
class PlainField {
constructor() {
this.prop = 0;
}
}
class MethodGetSet {
constructor() {
this._prop = 0;
}
getProp() {
return this._prop;
}
setProp(value) {
this._prop = value;
}
}
class AccessorProp {
constructor() {
this._prop = 0;
}
get prop() {
return this._prop;
}
set prop(value) {
this._prop = value;
}
}
class DefinePropertyAccessor {
constructor() {
this._prop = 0;
}
}
Object.defineProperty(DefinePropertyAccessor.prototype, "prop", {
get: function () {
return this._prop;
},
set: function (val) {
this._prop = val;
},
configurable: true
});
class LegacyDefineGetter {
constructor() {
this._prop = 0;
}
}
LegacyDefineGetter.prototype.__defineGetter__("prop", function () {
return this._prop;
});
LegacyDefineGetter.prototype.__defineSetter__("prop", function (val) {
this._prop = val;
});
class CombinedMethod {
constructor() {
this._prop = 0;
}
prop(value) {
if (value !== void 0) this._prop = value;
else return this._prop;
}
}
class GenericKeyedGetSet {
constructor() {
this._prop = 0;
}
get(key) {
return this[key];
}
set(key, value) {
this[key] = value;
}
}
class AttributesBagAccessor {
constructor() {
this.attributes = { prop: 0 };
}
get prop() {
return this.attributes.prop;
}
set prop(value) {
this.attributes.prop = value;
}
}
class DefinePropertyMethods {
constructor() {
this._prop = 0;
}
}
Object.defineProperty(DefinePropertyMethods.prototype, "getProp", {
value: function () {
return this._prop;
},
configurable: true
});
Object.defineProperty(DefinePropertyMethods.prototype, "setProp", {
value: function (val) {
this._prop = val;
},
configurable: true
});
class PrivateFieldAccessor {
#prop = 0;
get prop() {
return this.#prop;
}
set prop(v) {
this.#prop = v;
}
}
global.c1 = new PlainField();
global.c2 = new MethodGetSet();
global.c3 = new AccessorProp();
global.c4 = new DefinePropertyAccessor();
global.c5 = new LegacyDefineGetter();
global.c6 = new CombinedMethod();
global.c7 = new GenericKeyedGetSet();
global.c8 = new AttributesBagAccessor();
global.c9 = new DefinePropertyMethods();
global.c10 = new PrivateFieldAccessor();
})();
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Plain public field | | ready |
| Method getter + method setter | | ready |
| ES6 accessor property (get/set syntax) | | ready |
| Prototype accessor (Object.defineProperty) | | ready |
| Prototype accessor (__defineGetter__/__defineSetter__) | | ready |
| Combined getter/setter method | | ready |
| Generic keyed get/set reading/writing instance slots | | ready |
| “Attributes bag” property access via accessor forwarding | | ready |
| Methods installed via defineProperty | | ready |
| Private field accessor | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.