Object property order

Benchmark created on


Setup

const ordered = [];
const unordered = [];

for (let i = 0; i < 6; i++) {
	const x = Math.random();
	const y = Math.random();
	const z = Math.random();
	
	ordered.push({x, y, z});

	if (i === 0) {
		unordered.push({x, y, z});
	} else if (i === 1) {
		unordered.push({x, z, y});
	} else if (i === 2) {
		unordered.push({y, x, z});
	} else if (i === 3) {
		unordered.push({y, z, x});
	} else if (i === 4) {
		unordered.push({z, x, y});
	} else {
		unordered.push({z, y, x});
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
Ordered properties
const result = ordered.reduce((a, b) => ({x: a.x + b.x, y: a.y + b.y, z: a.z + b.z}), {x: 0, y: 0, z: 0})
ready
Unordered properties
const result = unordered.reduce((a, b) => ({x: a.x + b.x, y: a.y + b.y, z: a.z + b.z}), {x: 0, y: 0, z: 0})
ready

Revisions

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