test speed

Benchmark created on


Setup

export function groupBy(xs: any, key: any) {
  return xs.reduce(function (acc: any, x: any) {
    (acc[x[key]] = acc[x[key]] || []).push(x);
    return acc;
  }, {});
}

export function groupByMultipleKeys(xs: any, keys: string[]) {
  return xs.reduce((acc: any, x: any) => {
    keys.forEach(key => {
      const keyValue = x[key];
      if (!acc[key]) {
        acc[key] = {};
      }
      if (!acc[key][keyValue]) {
        acc[key][keyValue] = [];
      }
      acc[key][keyValue].push(x);
    });
    return acc;
  }, {});
}


Test runner

Ready to run.

Testing in
TestOps/sec
before
groupBy(response, 'scenario');
groupBy(response, 'process');
groupBy(response, 'entity');
groupBy(response, 'data')
groupBy(response, 'grain')
ready
after
groupByMultipleKeys(response, ['scenario', 'process', 'entity', 'data', 'grain'])
ready

Revisions

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