reduce vs loop

Benchmark created on


Setup

const arr = [];
for (let i = 0; i < 5000; i++) {
  arr.push({key:`key${i}`, value:`value${i}`});
}

Test runner

Ready to run.

Testing in
TestOps/sec
loop

  const map = new Map();
  for (let i = 0; i < arr.length; i++) {
    map.set(arr[i].key, arr[i]);
  }
ready
reduce
arr.reduce((acc, val) => acc.set(val.key, val), new Map());
ready

Revisions

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