Interval Distribution

Benchmark created by Kia Fathi on


Setup

const fib = x => (x > 1 ? fib(x - 1) + fib(x - 2) : x);
  const intervals = [
    {
      action: () => {
        fib(15);
      },
      interval: 5,
    },
    {
      action: () => {
        fib(15);
      },
      interval: 7,
    },
    {
      action: () => {
        fib(15);
      },
      interval: 8,
    },
    {
      action: () => {
        fib(5);
      },
      interval: 10,
    },
    {
      action: () => {
        fib(14);
      },
      interval: 9,
    },
    {
      action: () => {
        fib(4);
      },
      interval: 6,
    },
    {
      action: () => {
        fib(3);
      },
      interval: 3,
    },
    {
      action: () => {
        fib(25);
      },
      interval: 4,
    },
    {
      action: () => {
        fib(35);
      },
      interval: 5,
    },
    {
      action: () => {
        fib(15);
      },
      interval: 25,
    },
    {
      action: () => {
        fib(15);
      },
      interval: 5,
    },
    {
      action: () => {
        fib(15);
      },
      interval: 13,
    },
  ];
  
  const testDuration = 20 * 1000;

Test runner

Ready to run.

Testing in
TestOps/sec
strategy1
const strategy1 = () => {
  const ids = intervals.map(int =>
    setInterval(int.action, int.interval * 1000)
  );
  setTimeout(() => {
    ids.forEach(int => clearInterval(int));
    deferred.resolve();
    return;
  }, testDuration);
};
ready
strategy2
const strategy2 = () => {
  let beat = 0;
  const register = () => {
    beat += 1;
    intervals.forEach(int => {
      if (int.interval % beat === 0) {
        int.action();
      }
    });
  };
  const id = setInterval(register, 1000);
  setTimeout(() => {
    clearInterval(id);
    deferred.resolve();
    return;
  }, testDuration);
};
ready

Revisions

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

  • Revision 1: published by Kia Fathi on