AOS

Benchmark created on


Setup

function makePoint() {
	return { x: Math.random(), y: Math.random() };
}
function makeBounds() {
	return { start: makePoint(), end: makePoint() };
}
function makeMetadata() {
	return { color: `${Math.random()}` };
}
function makeId() { return (Math.random() * (2**30)) | 0; }

function makeShape() {
	return {
		id: makeId(),
		typeId: makeId(),
		bounds: makeBounds(),
		metadata: makeMetadata(),
	}
}

const len = 30_000;
const aos = Array();
for (let i = 0; i < len; i++) {
	aos.push(makeShape());
}

const soa = {
	ids: new Int32Array(len),
	typeIds: new Int32Array(len),
	startX: new Float64Array(len),
	endX: new Float64Array(len),
	startY: new Float64Array(len),
	endY: new Float64Array(len),
}
for (let i = 0; i < len; i++) {
	soa.ids[i] = aos[i].id;
	soa.typeIds[i] = aos[i].typeId;
	soa.startX[i] = aos[i].bounds.start.x;
	soa.endX[i] = aos[i].bounds.end.x;
	soa.startY[i] = aos[i].bounds.start.y;
	soa.endY[i] = aos[i].bounds.start.y;
}

Test runner

Ready to run.

Testing in
TestOps/sec
AOS max Y
let max = Number.NEGATIVE_INFINITY;
for (let i = 0; i < len; i++) {
	max = Math.max(max, aos[i].bounds.start.y);
	max = Math.max(max, aos[i].bounds.end.y);
}
ready
SOA max Y
let max = Number.NEGATIVE_INFINITY;
for (let i = 0; i < len; i++) {
	max = Math.max(max, soa.startY[i]);
	max = Math.max(max, soa.endY[i]);
}
ready

Revisions

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