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

Revision 2 of this benchmark created on


Setup

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

function groupBy(b, c) {
  const d = {};
  for (const e of b) (d[c(e)] ||= []).push(e);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Object.groupBy()
const b = Object.groupBy(a, (c) => c < 5000 ? "c" : "d");
ready
Object.groupBy() implementation
const b = 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.