Array vs object

Benchmark created on


Setup

const LENGTH = 100
const arr = Array.from({ length: LENGTH }).map((x, index) => index);
const obj = arr.reduce((acc, x) => ({ ...acc, [x]: true }), {});
const set = new Set(arr);

Test runner

Ready to run.

Testing in
TestOps/sec
Arr
for (let i = 0; i < LENGTH; i++) {
	const found = arr.includes(i)
	if (found) {
		const b = 1
	}
}
ready
Obj
for (let i = 0; i < LENGTH; i++) {
	const found = obj[i]
	if (found) {
		const b = 1
	}
}
ready
Set
for (let i = 0; i < LENGTH; i++) {
	const found = set.has(i)
	if (found) {
		const b = 1
	}
}
ready

Revisions

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