obj vs. class

Benchmark created on


Setup

class C {
	x;
	y;
	z;
	constructor({x, y, z = false}) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
objs
for (var i = 0; i < 10000; i++) {
	let o;
	if (i % 2 === 0) {
		o = {x: 1, y: 2};
	} else {
		o = {y: 2, z: true, x: 1};
	}
	o.x + o.y + (o.z ? 0 : 1);
}
ready
classes
for (var i = 0; i < 10000; i++) {
	let o;
	if (i % 2 === 0) {
		o = new C({x: 1, y: 2});
	} else {
		o = new C({y: 2, z: true, x: 1});
	}
	o.x + o.y + (o.z ? 0 : 1);
}
ready

Revisions

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