spread

Benchmark created on


Setup

function createMsg() {
  return { mid: crypto.randomUUID() };
}

var count = 400000;
var all = Array.from({ length: count }).map(() => createMsg());

var before = {
  lists: {
    'group-1': all.slice(0, count / 2).map(item => item.mid),
    'group-2': all.slice(count / 2).map(item => item.mid),
  },
  messages: Object.fromEntries(all.map(item => [item.mid, item])),
};

var after = {
  messages: {
    'group-1': Object.fromEntries(all.slice(0, count / 2).map(item => [item.mid, item])),
    'group-2': Object.fromEntries(all.slice(count / 2).map(item => [item.mid, item])),
  },
};

Test runner

Ready to run.

Testing in
TestOps/sec
1
var newMsg = createMsg();
before = {
  lists: { ...before.lists, 'group-1': [...before.lists['group-1'], newMsg.mid] },
  messages: { ...before.messages, [newMsg.mid]: newMsg },
};
ready
2
var newMsg = createMsg();
after = {
  messages: { ...after.messages, 'group-1': { [newMsg.mid]: newMsg } },
};
ready

Revisions

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