iterator.find vs for-loop with if

Benchmark created on


Setup

const map = new Map();
Array.from({ length: 100_000 }).forEach((id) => {
  map.set(id, { id, data: "data-" + id });
});

Test runner

Ready to run.

Testing in
TestOps/sec
iterator.find
return map.values().find((x) => x.data === "data-50000");
ready
interator with for and if
for (const value of map.values()) {
  if (value.data === "data-50000") return value;
}
ready

Revisions

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