map or find (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
var accruals = [
 { petId: 0 },
 { petId: 1 },
 { petId: 2 },
 { petId: 3 },
 { petId: 4 },
 { petId: 5 },
 ];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
map
const map = accruals.reduce((acc, it)=>{
	Object.assign(acc, { [it.petId]: it });
	return acc;
}, {});

for(let i = 0; i<10; i++) {
const index = Math.trunc(Math.random()*6);
const pet = map[index];
}
ready
find
for(let i = 0; i<10; i++) {
  const index = Math.trunc(Math.random()*6);
  const pet = accruals.find((it) => it.petId === index);
}
ready

Revisions

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