benchWith purescript-backend-optimizer

I’m trying the purescript-parsing benchmarks with purs-backend-es and the difference is so absurd that I’m sure the benchWith arguments are being removed because it’s code which “we know for certain is not demanded.”

Any tips for how to prevent the benchmark loops from being removed?

purs

purs-backend-es

runParser many digit 10000
mean   = 6.62 ms
stddev = 2.77 ms
min    = 5.41 ms
max    = 22.57 ms
runParser many digit 10000
mean   = 2.63 μs
stddev = 13.23 μs
min    = 214.00 ns
max    = 91.69 μs
runParser Array.many digit 10000
mean   = 65.85 ms
stddev = 3.92 ms
min    = 61.14 ms
max    = 79.15 ms
runParser Array.many digit 10000
mean   = 209.60 ns
stddev = 147.29 ns
min    = 172.00 ns
max    = 1.22 μs
StringParser manyRec CodePoints.anyDigit 10000
mean   = 5.99 ms
stddev = 2.60 ms
min    = 4.34 ms
max    = 15.32 ms
StringParser manyRec CodePoints.anyDigit 10000
mean   = 250.55 ns
stddev = 242.06 ns
min    = 187.00 ns
max    = 1.28 μs

Non-minified generated benchWith function looks like this. The f argument is never called.

var benchWith$p = (n) => (f) => () => {
  const sumRef = { value: 0 };
  const sum2Ref = { value: 0 };
  const minRef = { value: infinity };
  const maxRef = { value: 0 };
  gc();
  forE(0)(n)((v) => () => {
    const t1 = hrTime([0, 0]);
    const t2 = hrTime(t1);
    const ns = fromHrTime(t2);
    const $11 = sumRef.value;
    sumRef.value = $11 + ns;
    const $13 = sum2Ref.value;
    sum2Ref.value = $13 + ns * ns;
    const $15 = minRef.value;
    minRef.value = min($15)(ns);
    const $17 = maxRef.value;
    maxRef.value = max($17)(ns);
    return unit;
  })();
  const sum = sumRef.value;
  const sum2 = sum2Ref.value;
  const min$p = minRef.value;
  const max$p = maxRef.value;
  const n$p = toNumber(n);
  const mean = sum / n$p;
  return { mean, stdDev: sqrt((sum2 - n$p * mean * mean) / (n$p - 1)), min: min$p, max: max$p };
};

You’ll need to use this branch Update FFI to be more portable and direct. by natefaubion · Pull Request #25 · purescript/purescript-minibench · GitHub

2 Likes