(xs: number[])
| 32 | const MEASURED_RUNS = 5; |
| 33 | |
| 34 | function median(xs: number[]): number { |
| 35 | const sorted = [...xs].sort((a, b) => a - b); |
| 36 | const mid = Math.floor(sorted.length / 2); |
| 37 | return sorted.length % 2 === 0 |
| 38 | ? (sorted[mid - 1] + sorted[mid]) / 2 |
| 39 | : sorted[mid]; |
| 40 | } |
| 41 | |
| 42 | /** Median time of `MEASURED_RUNS` runs of `fn()`, in ms. */ |
| 43 | function bench(fn: () => void, warmup = 3): number { |