Using spread on the accumulator in a `reduce` method

Benchmark created on


Setup

const arr = Array.from(Array(100).keys())

Test runner

Ready to run.

Testing in
TestOps/sec
Using the spread operator
arr.reduce(
  (acc, key) => ({
  	...acc,
  	[key]: key,
  }),
  {}
);
ready
Mutating the accumulator directly
arr.reduce(
  (acc, key) => {
  	acc[key] = key;
  	return acc;
  },
  {}
);
ready

Revisions

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