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 Base1 extends Base {}
class Base2 extends Base1 {}
class Base3 extends Base2 {}
class Base4 extends Base3 {}
class Base5 extends Base4 {}
class Base6 extends Base5 {}
class Base7 extends Base6 {}
class Base8 extends Base7 {}
class Base9 extends Base8 {}
class BaseA extends Base9 {}
class BaseB extends BaseA {}
class BaseC extends BaseB {}
class BaseD extends BaseC {}
class BaseE extends BaseD {}
class BaseF extends BaseE {}
class Child extends BaseF {
retrieveChild(x) {
return {
a: this.values[x],
b: this.values[x+1],
c: this.values[x+2],
d: this.values[x+3],
};
}
retrieveProp2(x) {
return super.retrieveProp(x);
}
retrieveDirect(array, x) {
return {
a: array[x],
b: array[x+1],
c: array[x+2],
d: array[x+3],
};
}
static retrieveStatic(array, x) {
return {
a: array[x],
b: array[x+1],
c: array[x+2],
d: array[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 |
Child class, Super method |
| ready |
inline Child, Base |
| ready |
inline Base, Base |
| ready |
Child class, array ref |
| ready |
Child class, Static method, array ref |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.