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 array = [...typed];
var acc = 0;
function getVar(x) {
return {
a: array[x],
b: array[x + 1],
c: array[x + 2],
d: array[x + 3],
};
}
function getRef(array, x) {
return {
a: array[x],
b: array[x + 1],
c: array[x + 2],
d: array[x + 3],
};
}
class Base {
array;
constructor(array) {
this.array = array;
}
getThis(x) {
return {
a: this.array[x],
b: this.array[x + 1],
c: this.array[x + 2],
d: this.array[x + 3],
};
}
getRef(array, x) {
return {
a: array[x],
b: array[x + 1],
c: array[x + 2],
d: array[x + 3],
};
}
static getStaticVar(x) {
return {
a: array[x],
b: array[x + 1],
c: array[x + 2],
d: array[x + 3],
};
}
static getStaticRef(array, x) {
return {
a: array[x],
b: array[x + 1],
c: array[x + 2],
d: array[x + 3],
};
}
}
var base = new Base(array);
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 {
childThis(x) {
return {
a: this.array[x],
b: this.array[x + 1],
c: this.array[x + 2],
d: this.array[x + 3],
};
}
childSuper(x) {
return super.getThis(x);
}
}
var child = new Child(array);
Ready to run.
Test | Ops/sec | |
---|---|---|
function getVar(x) |
| ready |
base.getThis(x) |
| ready |
child.getThis(x) |
| ready |
child.childThis(x) |
| ready |
child.childSuper(x) |
| ready |
function getRef(array, x) |
| ready |
base.getRef(array, x) |
| ready |
child.getRef(array, x) |
| ready |
Base.getStaticVar(x) |
| ready |
Child.getStaticVar(x) |
| ready |
Base.getStaticRef(x) |
| ready |
Child.getStaticRef(x) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.