Object assign vs spread

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Spread
(function () {
  const items = Array.from({ length: 5000 }, (_, i) => i);
  return items.reduce((acc, i) => {
    return { ...acc, ["k" + i]: i };
  }, {});
})();
ready
Reduce
(function () {
  const items = Array.from({ length: 5000 }, (_, i) => i);
  return items.reduce((acc, i) => {
    return acc["k" + i] = i;
    return acc;
  }, {});
})();
ready

Revisions

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