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

Revision 3 of this benchmark created on


Setup

const data = [...Array(15).keys().map(String)];
const 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;
}, {});
Object.assign(accumulator, reduced);
ready
Object assign
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.