Estimates the cost of a single provider.fn() call by repeatedly measuring
back-to-back pairs and reducing the strictly-positive deltas to a single
value via the chosen estimator.
Coarse-timer detection. When the timer resolution R exceeds the call
cost C (C < R / 2), the probability that any pair crosses a tick
boundary is C / R < 1 / 2, so most pairs return a delta of zero. The
positive deltas that do occur each equal exactly one tick R, not the
call cost. To prevent catastrophic over-correction, the function returns
0 whenever fewer than half of the pairs produce a positive delta.
Bigint precision. The subtraction is performed in the provider's
native type before conversion to milliseconds (toMs(b - a)). For
hrtimeNow, this preserves precision when absolute timestamps exceed
Number.MAX_SAFE_INTEGER ns (≈ 104 days uptime).
JIT warmup. A discarded warmup phase ensures fn and toMs are
JIT-compiled to their steady-state tier before measurements begin.
Estimates the cost of a single
provider.fn()call by repeatedly measuring back-to-back pairs and reducing the strictly-positive deltas to a single value via the chosen estimator.Coarse-timer detection. When the timer resolution
Rexceeds the call costC(C < R / 2), the probability that any pair crosses a tick boundary isC / R < 1 / 2, so most pairs return a delta of zero. The positive deltas that do occur each equal exactly one tickR, not the call cost. To prevent catastrophic over-correction, the function returns0whenever fewer than half of the pairs produce a positive delta.Bigint precision. The subtraction is performed in the provider's native type before conversion to milliseconds (
toMs(b - a)). ForhrtimeNow, this preserves precision when absolute timestamps exceedNumber.MAX_SAFE_INTEGERns (≈ 104 days uptime).JIT warmup. A discarded warmup phase ensures
fnandtoMsare JIT-compiled to their steady-state tier before measurements begin.