Skip to content

Commit 71088d9

Browse files
committed
use Ir median as main metrics
1 parent 80ba146 commit 71088d9

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

benchmark/benchmark.php

+11-12
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,24 @@ function runValgrindPhpCgiCommand(
139139
// print all collected metrics
140140
print_r(array_map(fn ($metrics) => array_map(fn ($v) => number_format($v, 0, '.', '_'), $metrics), $metricsArr));
141141

142-
// find the fastest benchmark run
143-
$bestRunIndex = 0;
144-
foreach (range(0, $repeat - 1) as $k) {
145-
if ($metricsArr[$k]['Ir'] < $metricsArr[$bestRunIndex]['Ir']) {
146-
$bestRunIndex = $k;
147-
}
148-
}
149-
150-
// remove non-fastest profiles from artifacts
142+
// find median benchmark run
143+
$metricsForMedianArr = $metricsArr;
144+
unset($metricsForMedianArr['startup']);
145+
unset($metricsForMedianArr['shutdown']);
146+
uasort($metricsForMedianArr, fn ($a, $b) => $a['Ir'] <=> $b['Ir']);
147+
$medianRunIndex = array_key($metricsForMedianArr)[max(0, floor((count($metricsForMedianArr) - 3 /* -1 for count to index, -1 for first slow run due compliation, -1 for second run which is a little slower too */) / 2.0))];
148+
149+
// remove non-median profiles from artifacts
151150
foreach (range(0, $repeat - 1) as $k) {
152151
$profileOutSpecific = $profileOut . '.' . $k;
153152

154-
if ($k !== $bestRunIndex) {
153+
if ($k !== $medianRunIndex) {
155154
unlink($profileOutSpecific);
156155
}
157156
}
158157

159158
// annotate profiles for artifacts
160-
foreach (['startup', $bestRunIndex, 'shutdown'] as $k) {
159+
foreach (['startup', $medianRunIndex, 'shutdown'] as $k) {
161160
$profileOutSpecific = $profileOut . '.' . $k;
162161

163162
runCommand([
@@ -171,7 +170,7 @@ function runValgrindPhpCgiCommand(
171170
]);
172171
}
173172

174-
return ['instructions' => $metricsArr[$bestRunIndex]['Ir']];
173+
return ['instructions' => $metricsArr[$medianRunIndex]['Ir']];
175174
}
176175

177176
/**

0 commit comments

Comments
 (0)