Assign each iteration vs. reduce then assign vs. fromEntries then assign (v4)

Revision 4 of this benchmark created on


Setup

const data = [...Array(15).keys().map(String)];
let accumulator = {};

Teardown

console.log(accumulator);

Test runner

Ready to run.

Testing in
TestOps/sec
ForEach
data.forEach((datum, index) => {
	accumulator[datum] = index;
});
ready
Reduce then assign
const reduced = data.reduce((acc, datum, index) => {
	acc[datum] = index;
	return acc;
}, accumulator);

ready
Object assign
accumulator = Object.fromEntries(data.map((datum, index) => {
   	return [datum, index];
}))
ready

Revisions

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