Array.some vs Set and custom setSome

Benchmark created on


Setup

const list = ["apple", "orange", "banana", "peach", "mango"];
const set = new Set(list);

const fruit = "strawberry";

const setSome = (set, predicate) => {
  for (const value of set) {
    if (predicate(value)) {
      return true;
    }
  }
  return false;
};

Test runner

Ready to run.

Testing in
TestOps/sec
Array.some
list.some(item =>
	fruit
		.toLowerCase()
		.includes(item.toLowerCase())
);
ready
Set and setSome
setSome(set, item =>
	fruit
      .toLowerCase()
      .includes(item.toLowerCase())
);
ready

Revisions

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