Reduce in-place vs. pure function

Benchmark created on


Setup

const N = 100000;
const nums = [...Array(100000).keys()];

Test runner

Ready to run.

Testing in
TestOps/sec
New object
const result = nums.reduce((acc, n) => ({
	...acc,
	[`${n}`]: n
}), {});
ready
In-place
const result = nums.reduce((acc, n) => {
	acc[`${n}`] = n;
	return acc;
}, {});
ready

Revisions

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