new-function-vs-call-function-vs-new-class

Benchmark created on


Setup

function A(x, y, z) {
	this.x = x;
	this.y = y;
	this.z = z;
}
function B(x, y, z) {
	if (!(this instanceof B)) {
		return new B(x, y, z);
	}
	this.x = x;
	this.y = y;
	this.z = z;
}
class C {
	constructor(x, y, z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
new function
for (let i = 0; i < 1000; i++) {
	new A(i, i+1, i-1)
}
ready
call function
for (let i = 0; i < 1000; i++) {
	B(i, i+1, i-1)
}
ready
new object
for (let i = 0; i < 1000; i++) {
	new C(i, i+1, i-1)
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.