diff --git a/benchmark/benchmark.php b/benchmark/benchmark.php index 0c2ac4c6010a4..787845f74bcc6 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'); @@ -136,6 +146,9 @@ 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'); 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);