arr vs "struct" vs typed arr

Benchmark created on


Setup

const a = [];
const b = [];
const c = [];
const d = new Int32Array(10_000);
const e = new Int32Array(10_000);

for (let i = 0; i < 10_000; ++i) {
	a[i] = i;
	b[i] = i;
	
	c[i] = { a: i, b: i};
	
	d[i] = i;
	e[i] = i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
sum numeric arrays
const nacc = [];
for (let i = 0; i < 10_000; ++i) {
		nacc[i] = a[i] + b[i];
}
ready
sum object properties
const oacc = [];
for (let i = 0; i < 10_000; ++i) {
	const { a, b } = c[i];
		oacc[i] = a + b;
}
ready
sum typed array
const aacc = [];
for (let i = 0; i < 10_000; ++i) {
		aacc[i] = d[i] + e[i];
}
ready

Revisions

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