Commit a9b871f
committed
fix(bench): correct percentile calculation using nearest-rank method
Fixed incorrect percentile index calculation in calculate_statistics():
Previous (incorrect):
- p50_idx = (n * 0.50) as usize
- For 100 samples: idx=50 → accesses 51st value (should be 50th)
- Used .min(len-1) as a band-aid to prevent out-of-bounds
Current (correct, nearest-rank):
- p50_idx = ceil(n * 0.50) - 1
- For 100 samples: ceil(50.0) - 1 = 49 → accesses 50th value ✓
- Uses saturating_sub(1) to handle edge cases
The nearest-rank method is standard for benchmark percentile calculations
and ensures we access the correct element in the sorted array.
Examples:
- n=100, p50: ceil(50.0)-1 = 49 (50th percentile)
- n=100, p95: ceil(95.0)-1 = 94 (95th percentile)
- n=100, p99: ceil(99.0)-1 = 98 (99th percentile)1 parent 7117001 commit a9b871f
1 file changed
+9
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
| |||
0 commit comments