Array vs object (v2)

Revision 2 of this benchmark created on


Setup

const LENGTH = 1000
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)
}
ready
Obj
for (let i = 0; i < LENGTH; i++) {
	const found = obj[i]
}
ready
Set
for (let i = 0; i < LENGTH; i++) {
	const found = set.has(i)
}
ready
Arr - findIndex
for (let i = 0; i < LENGTH; i++) {
	const found = arr.findIndex(x => x === i) !== -1
}
ready

Revisions

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