CacheLocality

Benchmark created on


Description

Tests to benchamark data locality between arrays, map entries, map keys, map values, object entries, object values. This is used to determine best approach for iterations.

Setup

const array = [];
const map = new Map();
const sum = 0;
for (let i = 0; i < 10000; i++) {
	const obj = {id: i, a:Math.random(), b:Math.random(), r:0};
	array.push(obj);
	map.set(obj.id, obj);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Array for
array.forEach((o, index) => {
	o.r = o.a+o.b;
	sum += o.r;
});
ready
Map entries
for(const [id, o] of map.entries) {
	o.r = o.a+o.b;
	sum += o.r;
}
console.log(sum);
ready

Revisions

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