spread operator evaluation

Benchmark created on


Description

testing speed of spread

Setup

const baseNames = ["Ash", "Bree", "Carl", "Dexter", "Ethan"];
const names = [];

for (let i = 0; i < 10000; i++) {
  const name = baseNames[i % baseNames.length] + Math.floor(i / baseNames.length);
  names.push(name);
}

Test runner

Ready to run.

Testing in
TestOps/sec
With spread
const nameLookup = names.reduce(
	(acc, curr) => ({ ...acc, [curr]: true }), {}
);
console.log(nameLookup);
ready
Without spread
const nameLookup = names.reduce(
	(acc, curr) => {
		acc[curr] = true;
		return acc;
	}, {}
);
console.log(nameLookup);
ready
with map
const nameLookup = names.map(
	(item) => ({ [item]: true })
);
console.log(nameLookup);
ready

Revisions

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