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 typed = new Int32Array(size);
crypto.getRandomValues(typed);
var acc = 0;
function getVar(x) {
return {
a: typed[x],
b: typed[x + 1],
c: typed[x + 2],
d: typed[x + 3],
};
}
class Generic {
callback;
constructor(callback) {
this.callback = callback;
}
getCall(x) {
return {
a: this.callback(x),
b: this.callback(x + 1),
c: this.callback(x + 2),
d: this.callback(x + 3),
};
}
}
var generic = new Generic(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(typed);
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(typed);
class Typed {
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 typed = new Typed(typed);
Ready to run.
Test | Ops/sec | |
---|---|---|
function getVar(x) |
| ready |
generic.getCall(x) |
| ready |
arrayRef.getThis(x) |
| ready |
typeHint.getThis(x) |
| ready |
typed.getThis(x) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.