From d09ba211898a9f0970eee40ecd06960aedf1ff49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 2 Apr 2026 12:27:53 +0200 Subject: [PATCH 1/4] improve return type --- benchmark/benchmark.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/benchmark/benchmark.php b/benchmark/benchmark.php index 0c2ac4c6010a4..9b92edb1493df 100644 --- a/benchmark/benchmark.php +++ b/benchmark/benchmark.php @@ -136,9 +136,15 @@ function runValgrindPhpCgiCommand( return ['instructions' => $instructions]; } +/** + * @return decimal-int-string + */ function extractInstructionsFromValgrindOutput(string $output): string { - preg_match("(==[0-9]+== Events : Ir\n==[0-9]+== Collected : (?[0-9]+))", $output, $matches); - return $matches['instructions'] ?? throw new \Exception('Unexpected valgrind output'); + if (!preg_match("(==[0-9]+== Events : Ir\n==[0-9]+== Collected : (?[0-9]+))", $output, $matches)) { + throw new \Exception('Unexpected valgrind output'); + } + + return $matches['instructions']; } main(); From 285325c8de3967cadf625902ab28a729714ecb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 2 Apr 2026 12:28:32 +0200 Subject: [PATCH 2/4] check extensions for exact purpose --- benchmark/benchmark.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/benchmark/benchmark.php b/benchmark/benchmark.php index 9b92edb1493df..21e39e372efe9 100644 --- a/benchmark/benchmark.php +++ b/benchmark/benchmark.php @@ -2,11 +2,7 @@ require_once __DIR__ . '/shared.php'; -foreach (array("mbstring", "sockets", "mysqli", "openssl", "gmp") as $ext) { - if (!extension_loaded($ext)) { - throw new LogicException("Extension $ext is required."); - } -} +checkExtensions(['gmp']); $storeResult = ($argv[1] ?? 'false') === 'true'; $phpCgi = $argv[2] ?? dirname(PHP_BINARY) . '/php-cgi'; @@ -27,12 +23,18 @@ function main() { if (false !== $branch = getenv('GITHUB_REF_NAME')) { $data['branch'] = $branch; } + $data['Zend/bench.php'] = runBench(false); $data['Zend/bench.php JIT'] = runBench(true); + + checkExtensions(['mbstring']); $data['Symfony Demo 2.2.3'] = runSymfonyDemo(false); $data['Symfony Demo 2.2.3 JIT'] = runSymfonyDemo(true); + + checkExtensions(['mbstring', 'sockets', 'mysqli', 'openssl']); $data['Wordpress 6.2'] = runWordpress(false); $data['Wordpress 6.2 JIT'] = runWordpress(true); + $result = json_encode($data, JSON_PRETTY_PRINT) . "\n"; fwrite(STDOUT, $result); @@ -42,6 +44,14 @@ function main() { } } +function checkExtensions(array $extensions): void { + foreach ($extensions as $ext) { + if (!extension_loaded($ext)) { + throw new LogicException("Extension $ext is required."); + } + } +} + function storeResult(string $result) { $repo = __DIR__ . '/repos/data'; cloneRepo($repo, 'git@github.com:php/benchmarking-data.git'); From 6cc453b672b6f1507bca788365c04b05aefb62f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 2 Apr 2026 15:14:15 +0200 Subject: [PATCH 3/4] revert cs change --- benchmark/benchmark.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/benchmark/benchmark.php b/benchmark/benchmark.php index 21e39e372efe9..787845f74bcc6 100644 --- a/benchmark/benchmark.php +++ b/benchmark/benchmark.php @@ -150,11 +150,8 @@ function runValgrindPhpCgiCommand( * @return decimal-int-string */ function extractInstructionsFromValgrindOutput(string $output): string { - if (!preg_match("(==[0-9]+== Events : Ir\n==[0-9]+== Collected : (?[0-9]+))", $output, $matches)) { - throw new \Exception('Unexpected valgrind output'); - } - - return $matches['instructions']; + preg_match("(==[0-9]+== Events : Ir\n==[0-9]+== Collected : (?[0-9]+))", $output, $matches); + return $matches['instructions'] ?? throw new \Exception('Unexpected valgrind output'); } main(); From 97dce0e6498b8ae4b865382aae3bc9c0f6d59732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 2 Apr 2026 14:45:02 +0200 Subject: [PATCH 4/4] make ProcessResult class readonly --- benchmark/shared.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/benchmark/shared.php b/benchmark/shared.php index 0f58a2a1bf870..107e097fb176c 100644 --- a/benchmark/shared.php +++ b/benchmark/shared.php @@ -1,14 +1,15 @@ ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; if ($printCommand) { fwrite(STDOUT, "> $cmd\n"); @@ -24,6 +25,8 @@ function runCommand(array $args, ?string $cwd = null, bool $printCommand = true) stream_set_blocking($stdout, false); stream_set_blocking($stderr, false); + $stdoutStr = ''; + $stderrStr = ''; $stdoutEof = false; $stderrEof = false; @@ -37,9 +40,9 @@ function runCommand(array $args, ?string $cwd = null, bool $printCommand = true) foreach ($read as $stream) { $chunk = fgets($stream); if ($stream === $stdout) { - $result->stdout .= $chunk; + $stdoutStr .= $chunk; } elseif ($stream === $stderr) { - $result->stderr .= $chunk; + $stderrStr .= $chunk; } } @@ -50,6 +53,8 @@ function runCommand(array $args, ?string $cwd = null, bool $printCommand = true) fclose($stdout); fclose($stderr); + $result = new ProcessResult($stdoutStr, $stderrStr); + $statusCode = proc_close($processHandle); if ($statusCode !== 0) { fwrite(STDOUT, $result->stdout);