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
Does extending a class add method call overhead?
var size = 16384;
var typed = new Int32Array(size);
crypto.getRandomValues(typed);
var acc = 0;
function retrieveProp(x) {
return {
a: typed[x],
b: typed[x+1],
c: typed[x+2],
d: typed[x+3],
};
}
class Base {
values;
constructor(values) {
this.values = values;
}
retrieveProp(x) {
return {
a: this.values[x],
b: this.values[x+1],
c: this.values[x+2],
d: this.values[x+3],
};
}
}
var base = new Base(typed);
class Child extends Base {
retrieveChild(x) {
return {
a: this.values[x],
b: this.values[x+1],
c: this.values[x+2],
d: this.values[x+3],
};
}
}
var child = new Child(typed);
function inlineProp(instance, x) {
return instance.retrieveProp(x);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
direct function |
| ready |
Base class |
| ready |
Child class, Child method |
| ready |
Child class, Base method |
| ready |
inline Child, Base |
| ready |
inline Base, Base |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.