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
Can we hint strongly to the JS engine about a class member type?
var size = 16384;
var typed32 = new Int32Array(size);
crypto.getRandomValues(typed32);
var acc = 0;
function getVar(x) {
return {
a: typed32[x],
b: typed32[x + 1],
c: typed32[x + 2],
d: typed32[x + 3],
};
}
class GetCall {
callback;
constructor(callback) {
this.callback = callback;
}
getThis(x) {
return {
a: this.callback(x),
b: this.callback(x + 1),
c: this.callback(x + 2),
d: this.callback(x + 3),
};
}
}
var getCall = new GetCall(getVar);
class ArrayRef {
array;
constructor(typed) {
this.array = typed;
}
getThis(x) {
return {
a: this.array[x],
b: this.array[x + 1],
c: this.array[x + 2],
d: this.array[x + 3],
};
}
}
var arrayRef = new ArrayRef(typed32);
class TypeHint {
typed;
constructor(typed) {
this.typed = typed ?? new Int32Array(size);
}
getThis(x) {
return {
a: this.typed[x],
b: this.typed[x + 1],
c: this.typed[x + 2],
d: this.typed[x + 3],
};
}
}
var typeHint = new TypeHint(typed32);
class MakeTyped {
typed;
constructor() {
this.typed = new Int32Array(size);
crypto.getRandomValues(this.typed);
}
getThis(x) {
return {
a: this.typed[x],
b: this.typed[x + 1],
c: this.typed[x + 2],
d: this.typed[x + 3],
};
}
}
var makeTyped = new MakeTyped(typed32);
Ready to run.
Test | Ops/sec | |
---|---|---|
function getVar(x) |
| ready |
getCall.getThis(x) |
| ready |
arrayRef.getThis(x) |
| ready |
typeHint.getThis(x) |
| ready |
makeTyped.getThis(x) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.