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
There is some kind of side-effect that we need to perform once when an Array is being accessed.
The idea is to either: keep track of whether or not the side-effect has been executed with a guard or to rewrite the array accessor.
There are two NOOP examples in here as well. They do not perform any additional work and therefore, are just present as a reference.
window.state = { prop: 0 };
if(undefined == Array.prototype.a) {
var sideEffect = function() {
++window.state.prop;
};
Array.prototype.a = function() { sideEffect(); return this; };
Array.prototype.b = function() {
if(this.init == true) {
return this;
}
sideEffect();
this.init = true;
return this;
};
Array.prototype.c = function() {
var t = this;
sideEffect();
t.c = function() { return t; }
return t;
};
Object.defineProperty(Array.prototype, 'd', {
get: function() { sideEffect(); return this; },
enumerable: false
});
Object.defineProperty(Array.prototype, '$init$', {
value: false,
enumerable: false
});
Object.defineProperty(Array.prototype, 'e', {
get: function() {
if(this.$init$) { return this; }
sideEffect();
this.$init$ = true;
return this;
},
enumerable: false
});
Object.defineProperty(Array.prototype, 'f', {
get: function() {
Object.defineProperty(this, 'f', {
value: this,
enumerable: false,
configurable: false
});
sideEffect();
return this;
},
enumerable: false,
configurable: true
});
}
var N = 1000;
var arr = [];
var brr = [];
var i = 0;
var CONTROL = 0|0;
for(;i<N;++i) {
CONTROL = (CONTROL + i | 0) + i | 0;
arr.push(i);
brr.push(i);
}
if(window.state.prop != 2) {
//console.log("test ko!");
} else {
//console.log("test ok!");
}
delete window.state;
Ready to run.
Test | Ops/sec | |
---|---|---|
No Condition in Function |
| ready |
Condition in Function |
| ready |
Re-Write Function |
| ready |
No Condition in Property |
| ready |
Condition in Property |
| ready |
Re-Write Property |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.