filter vs for

Benchmark created on


Setup

const ids = [];

for (let i = 0; i < 10000; i++) {
	ids.push(Math.random() > 0 ? Math.random().toString() : undefined);
}

Test runner

Ready to run.

Testing in
TestOps/sec
filter
const a = ids.filter((id) => !!id)

return a;
ready
for
    const res = [];
    for (const id of ids) {
      if (id) {
        res.push(id);
      }
    }
    return res;
ready

Revisions

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