spread (v4)

Revision 4 of this benchmark created on


Setup

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

var MESSAGE_COUNT = 10000;
var MAX_MESSAGE_COUNT_EVERY_SESSION = 20;
var SESSION_COUNT = MESSAGE_COUNT / MAX_MESSAGE_COUNT_EVERY_SESSION;
var ALL_MESSAGES = Array.from({ length: MESSAGE_COUNT }).map(() => createMsg());

var before = {
  lists: Object.fromEntries(
    Array.from({ length: SESSION_COUNT }).map((_, i) => [
      `group-${i}`,
      ALL_MESSAGES.slice(
        i * MAX_MESSAGE_COUNT_EVERY_SESSION,
        i * MAX_MESSAGE_COUNT_EVERY_SESSION + MAX_MESSAGE_COUNT_EVERY_SESSION,
      ),
    ]),
  ),
  messages: Object.fromEntries(ALL_MESSAGES.map(item => [item.mid, item])),
};

var after = {
  messages: Object.fromEntries(
    Array.from({ length: SESSION_COUNT }).map((_, i) => [
      `group-${i}`,
      Object.fromEntries(
        ALL_MESSAGES.slice(
          i * MAX_MESSAGE_COUNT_EVERY_SESSION,
          i * MAX_MESSAGE_COUNT_EVERY_SESSION + MAX_MESSAGE_COUNT_EVERY_SESSION,
        ).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.