Spread vs Mutation

Benchmark created on


Setup

const headers = Array(10).map(_ => (Math.random() * 100).toString());
const addHeaders = Array(10).map(_ => (Math.random() * 100).toString());

const rows = Array(100_000).map(_ => {
  const obj = {};
  headers.forEach(header => {
    obj[header] = Math.random();
  });
});

const scims = Array(100_000).map(_ => {
  const obj = {};
  addHeaders.forEach(header => {
    obj[header] = Math.random();
  });
});

Test runner

Ready to run.

Testing in
TestOps/sec
Spread
const newRows = rows.map((row, index) => ({...row, ...scims[index]}));
ready
Mutation
rows.forEach((row, index) => {
  const scim = scims[index];
  Object.keys(scim).forEach(key => { row[key] = scim[key] });
});
ready

Revisions

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