Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions benchmark/benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -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 : (?<instructions>[0-9]+))", $output, $matches);
return $matches['instructions'] ?? throw new \Exception('Unexpected valgrind output');
Expand Down
17 changes: 11 additions & 6 deletions benchmark/shared.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

class ProcessResult {
public $stdout;
public $stderr;
readonly class ProcessResult {
public function __construct(
public string $stdout,
public string $stderr,
) {}
}

function runCommand(array $args, ?string $cwd = null, bool $printCommand = true): ProcessResult {
$cmd = implode(' ', array_map('escapeshellarg', $args));
$pipes = null;
$result = new ProcessResult();
$descriptorSpec = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
if ($printCommand) {
fwrite(STDOUT, "> $cmd\n");
Expand All @@ -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;

Expand All @@ -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;
}
}

Expand All @@ -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);
Expand Down
Loading