Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tools/bench/lib/stats.mjs

1.3 KiB, 1 run

created by r1870400018:66243, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// Order statistics shared by the node-side bench tools.
2
3/// The nearest-rank percentile of an ascending array: the value at 1-based rank ceil(p * n / 100),
4/// so p50 of 1..50 is the 25th smallest and p95 the 48th. `null` for an empty array. `p * n` stays
5/// an integer for an integer `p`, so the division is exact where the rank is whole.
6export function nearestRank(sorted, p) {
7 const n = sorted.length;
8 if (!n) return null;
9 const rank = Math.min(n, Math.max(1, Math.ceil((p * n) / 100)));
10 return sorted[rank - 1];
11}
12
13/// The median of an unsorted array of numbers (the mean of the middle pair for an even count).
14export function median(values) {
15 const s = [...values].sort((a, b) => a - b);
16 const n = s.length;
17 if (!n) return null;
18 return n % 2 ? s[(n - 1) / 2] : (s[n / 2 - 1] + s[n / 2]) / 2;
19}
20
21/// The typing test's threshold for one percentile of typst.ts's time `t` (seconds):
22/// max(1.25 * t, t + 16 ms), per D-20261001-08. One 60 Hz frame is the floor at which a
23/// difference stops being visible, so the additive term governs while t is under 64 ms.
24export function typingThreshold(t) {
25 return Math.max(1.25 * t, t + 0.016);
26}
27
28/// Does the 16 ms floor, rather than the 1.25x ratio, set the threshold at `t`?
29export function floorBinds(t) {
30 return t + 0.016 > 1.25 * t;
31}