tinylibs / tinybench

🔎 A simple, tiny and lightweight benchmarking library!
MIT License
1.72k stars 36 forks source link

Incorrect quantile computation. #72

Open jerome-benoit opened 4 months ago

jerome-benoit commented 4 months ago

The implementation borrowed from mitata is incorrect and off by at least one for all quantiles.

Correct implementation:

const quantile = (arr, q) => {
  const base = (arr.length - 1) * q;
  const baseIndex = Math.floor(base);
  if (arr[baseIndex + 1] != null) {
    return (
      arr[baseIndex] +
      (base - baseIndex) * (arr[baseIndex + 1] - arr[baseIndex])
    );
  }
  return arr[baseIndex];
};

Upvote & Fund

Fund with Polar

Aslemammad commented 4 months ago

Interesting, could you send a PR with a test?