spread vs func

Benchmark created on


Setup

const users = [];

for (let i = 0; i < 10000; i++) {
  users.push({
    id: `user${i}`,
    name: `User ${i}`
  });
}

Teardown

users.splice(0, users.length);

Test runner

Ready to run.

Testing in
TestOps/sec
func
users
  .filter((user) => user.active)
  .map((user) => ({ [user.id]: user.name }))
  .reduce(Object.assign, {});
ready
spread
users.reduce((acc, curr) => {
    if (curr.active) {
        return acc
    }
    return {...acc, [curr.id]: curr.name}
});
ready

Revisions

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