fromEntries vs reduce

Benchmark created on


Setup

const arr = Array(1e6)
      .fill(void 0)
      .map((_, idx) => ({ 
      	key: idx, 
      	value: Math.random() 
      }));

Test runner

Ready to run.

Testing in
TestOps/sec
fromEntries
Object.fromEntries(arr.map(o => [o.key, o]))
ready
reduce
arr.reduce((acc, o) => {
	acc[o.key] = o;
	return o;
}, {})
ready

Revisions

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