Check time savings of reduce one-liner

Benchmark created on


Setup

const series = [
  { x: 1744156800000, y: 730 },
  { x: 1744243200000, y: 480 },
  { x: 1744329600000, y: 440 },
  { x: 1744416000000, y: 522 },
  { x: 1744502400000, y: 601 },
  { x: 1744588800000, y: 806 },
  { x: 1744675200000, y: 768 },
  { x: 1744761600000, y: 572 },
  { x: 1744848000000, y: 482 },
  { x: 1744934400000, y: 434 },
  { x: 1745020800000, y: 540 },
  { x: 1745107200000, y: 643 },
  { x: 1745193600000, y: 1206 },
  { x: 1745280000000, y: 1133 },
  { x: 1745366400000, y: 666 },
  { x: 1745452800000, y: 879 },
  { x: 1745539200000, y: 697 },
  { x: 1745625600000, y: 602 },
  { x: 1745712000000, y: 1133 },
  { x: 1745798400000, y: 802 },
  { x: 1745884800000, y: 675 },
  { x: 1745971200000, y: 613 },
  { x: 1746057600000, y: 627 },
  { x: 1746144000000, y: 451 },
  { x: 1746230400000, y: 595 },
  { x: 1746316800000, y: 619 },
  { x: 1746403200000, y: 672 },
  { x: 1746489600000, y: 659 },
  { x: 1746576000000, y: 611 },
  { x: 1746662400000, y: 545 }
];

Test runner

Ready to run.

Testing in
TestOps/sec
reduce one-liner
const isChartAllZeros = series.reduce((acc, dataPoint) => acc + dataPoint.y, 0) === 0;
ready
map and min/max
const chartValues = series.map(dataPoint => dataPoint.y);
  const isChartAllZeros = Math.max(...chartValues) === 0 && Math.min(...chartValues) === 0;
ready

Revisions

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