Commit bcebead
committed
fix(utils): make mToNsBigint tolerate fractional milliseconds
`mToNsBigint` did `BigInt(ms) * 1_000_000n`, which throws "RangeError: ...
not an integer" for a fractional `ms`. This is reachable via
`new Bench({ concurrency: 'task', time })` with a non-integer `time` /
`warmupTime` on the hrtime provider (Node's default): `withConcurrency`
calls `fromMs(time)` and the task silently ends up in `state: 'errored'`.
Round to the nearest nanosecond with `BigInt(Math.round(ms * 1e6))` —
identical for integer ms, no longer throwing on fractional ms. Add a
regression test.
Also document that the exported `hrtimeNow` narrows the absolute timestamp
to a number (lossy past ~104 days of uptime); prefer
`hrtimeNowTimestampProvider`.1 parent e3acdab commit bcebead
2 files changed
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
906 | 906 | | |
907 | 907 | | |
908 | 908 | | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
909 | 914 | | |
910 | 915 | | |
911 | 916 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
0 commit comments