Array iteration vs. Object.groupBy(); Dead simple case

Benchmark created on


Setup

const a = new Array(10000).fill(null).map((_,i)=>i);

Test runner

Ready to run.

Testing in
TestOps/sec
Array iteration
const b = {c:[],d:[]};
for (const e of a)
  if (e < 5000) b.c.push(e);
  else b.d.push(e);
ready
Object.groupBy()
const b = Object.groupBy(a, (c) => c < 5000 ? "c" : "d");
ready

Revisions

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