{"size": 2213, "ext": "js", "max_stars_repo_path": "ipc/ipc-electron/src/render.js", "max_stars_repo_name": "crossplatform-dev/xplat-benchmark", "max_stars_repo_stars_event_min_datetime": "2022-01-28T13:47:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T13:47:33.000Z", "max_issues_repo_path": "ipc/ipc-electron/src/render.js", "max_issues_repo_name": "crossplatform-dev/xplat-challenges", "max_issues_repo_issues_event_min_datetime": "2021-05-11T20:08:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-12T08:04:35.000Z", "max_forks_repo_path": "ipc/ipc-electron/src/render.js", "max_forks_repo_name": "crossplatform-dev/xplat-benchmark", "max_forks_repo_forks_event_min_datetime": "2022-02-20T09:47:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T09:47:09.000Z"}
{"max_stars_count": 3, "max_issues_count": 3, "max_forks_count": 1, "avg_line_length": 25.1477272727, "max_line_length": 148, "alphanum_fraction": 0.633529146}
const startBurst = () => {
  const totalMessages = parseInt(document.getElementById('messages').value);
  let received = 0;
  const startTime = Date.now();
  const messages = [];

  const onMessage = (event, arg) => {
    const end = Date.now();
    const message = arg;

    message.duration = end - message.start;
    messages.push(message);

    received++;

    if (received === totalMessages) {
      const totalTime = end - startTime;
      let durations = 0;

      comms.clear();

      for (const message of messages) {
        durations += message.duration;
      }
      const average = durations / messages.length;
      document.getElementById('results').innerText = `Total: ${totalTime.toFixed(2)}ms - avg message roundtrip: ${average.toFixed(2)}ms`;
    }
  }

  comms.onMessage(onMessage);

  for (let id = 1; id <= totalMessages; id++) {
    const message = { id, start: Date.now(), duration: 0 };

    comms.sendMessage(message);
  }
};

document.getElementById('start').addEventListener('click', startBurst);

const startSequential = () => {
  const totalMessages = parseInt(document.getElementById('messages').value);
  let received = 0;
  const messages = [];
  const startTime = performance.now();

  const sendMessage = (id) => {
    const message = { id, start: performance.now(), duration: 0 };

    comms.sendMessage(message);
  };

  const onMessage = (event, arg) => {
    const end = performance.now();
    const message = arg;

    if (!message) {
      return;
    }

    message.duration = end - message.start;
    messages.push(message);

    received++;

    if (received === totalMessages) {
      const totalTime = end - startTime;
      let durations = 0;

      comms.clear();

      for (const message of messages) {
        durations += message.duration;
      }
      const average = durations / messages.length;
      document.getElementById('results-sequential').innerText = `Total: ${totalTime.toFixed(2)}ms - avg message roundtrip: ${average.toFixed(2)}ms`;
    } else {
      sendMessage(received + 1);
    }
  };

  comms.onMessage(onMessage);

  sendMessage(received + 1);
};

document.getElementById('start-sequential').addEventListener('click', startSequential);
