Nested loop vs hashmap

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Nested loop
const arr1 = [];

for(let i = 0; i <= 10000; i++){
	arr1.push(i)
}

for(let i = 0; i <= 10000; i++){
	arr1.find(elem => elem === i)
}
ready
Object lookup
const arr1 = [];

for(let i = 0; i <= 10000; i++){
	arr1.push(i)
}

const obj = {};

arr1.forEach(elem => {
	obj[elem] = elem;
})

for(let i = 0; i <= 10000; i++){
	obj[i]
}
ready

Revisions

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