Skip to content

Commit eadfdc6

Browse files
committed
test: Increase bench iterations to 10,000 and format in one line
It takes only ~1s to run with PHP 8.1 on my new machine, which seems too short to be stable. Increase 10x for a more stable rate. The single line format make it easier to compare within the same terminal window by taking less vertical space, as well as e.g. more readily comparable in commit messages or Phab/Gerrit comments when before/after are aligned and below one another. Change-Id: Ie7ea0ea1e506c000397e1b90bf9d28e42b0779aa
1 parent 7f45021 commit eadfdc6

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

test/CSSJanusBenchmark.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ class CSSJanusBenchmark {
44

55
public function run() {
66
foreach (self::getFixtures() as $name => $data) {
7-
$iterations = 1000;
8-
$this->outputIntro($name, $data, $iterations);
7+
$iterations = 10_000;
98
$total = 0;
109
$max = -INF;
1110
$i = 0;
@@ -16,23 +15,23 @@ public function run() {
1615
$max = max($max, $took);
1716
$total += ( microtime(true) - $start) * 1000;
1817
}
19-
$this->outputStat($total, $max, $iterations);
18+
$this->outputStat($name, $data, $iterations, $total, $max);
2019
}
2120
}
2221

23-
protected function outputIntro($name, $data, $iterations) {
24-
echo "\n## {$name}\n"
25-
. "- data length: " . $this->formatSize(strlen($data)) . "\n"
26-
. "- data hash: " . hash('fnv132', $data) . "\n"
27-
. "- iterations: " . $iterations . "\n";
28-
}
29-
30-
protected function outputStat($total, $max, $iterations) {
22+
protected function outputStat($name, $data, $iterations, $total, $max) {
23+
$version = hash('fnv132', $data);
3124
$mean = $total / $iterations; // in milliseconds
3225
$ratePerSecond = 1.0 / ( $mean / 1000.0 );
33-
echo "- max: " . sprintf('%.2fms', $max) . "\n";
34-
echo "- mean: " . sprintf('%.2fms', $mean) . "\n";
35-
echo "- rate: " . sprintf('%.0f/s', $ratePerSecond) . "\n";
26+
27+
echo sprintf(
28+
"* %-35s iterations=%d max=%.2fms mean=%.2fms rate=%.0f/s\n",
29+
"$name ($version)",
30+
$iterations,
31+
$max,
32+
$mean,
33+
$ratePerSecond
34+
);
3635
}
3736

3837
private function formatSize($size) {

0 commit comments

Comments
 (0)