Array.filter (v4)

Revision 4 of this benchmark created on


Setup

const pool = [
  undefined,
  null,
  "a",
  "b",
  "",
  0,
  1,
  -1,
  2,
  3,
  4,
  10,
  Math.random,
];

const arrayToFilter = Array.from({ length: 10_000 }, () => {
  const v = pool[Math.floor(Math.random() * pool.length)];
  return typeof v === "function" ? v() * 20 - 10 : v;
});

Test runner

Ready to run.

Testing in
TestOps/sec
.filter((v) => v)
arrayToFilter.filter((v) => v)
ready
.filter(Boolean)
arrayToFilter.filter(Boolean)
ready

Revisions

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