Skip to content

Commit a7056c1

Browse files
committed
Add JIT benchmarks
1 parent 7823a20 commit a7056c1

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

benchmark/benchmark.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ function main() {
1313
global $storeResult;
1414

1515
$data = [];
16-
$data['Zend/bench.php'] = runBench();
17-
$data['Symfony Demo 2.2.3'] = runSymfonyDemo();
18-
$data['Wordpress 6.2'] = runWordpress();
16+
$data['Zend/bench.php'] = runBench(false);
17+
$data['Zend/bench.php JIT'] = runBench(true);
18+
$data['Symfony Demo 2.2.3'] = runSymfonyDemo(false);
19+
$data['Symfony Demo 2.2.3 JIT'] = runSymfonyDemo(true);
20+
$data['Wordpress 6.2'] = runWordpress(false);
21+
$data['Wordpress 6.2 JIT'] = runWordpress(true);
1922
$result = json_encode($data, JSON_PRETTY_PRINT) . "\n";
2023

2124
fwrite(STDOUT, $result);
@@ -43,21 +46,19 @@ function getPhpSrcCommitHash(): string {
4346
return $result->stdout;
4447
}
4548

46-
function runBench(): array {
47-
$process = runValgrindPhpCgiCommand([dirname(__DIR__) . '/Zend/bench.php']);
48-
return ['instructions' => extractInstructionsFromValgrindOutput($process->stderr)];
49+
function runBench(bool $jit): array {
50+
return runValgrindPhpCgiCommand([dirname(__DIR__) . '/Zend/bench.php'], jit: $jit);
4951
}
5052

51-
function runSymfonyDemo(): array {
53+
function runSymfonyDemo(bool $jit): array {
5254
$dir = __DIR__ . '/repos/symfony-demo-2.2.3';
5355
cloneRepo($dir, 'git@github.com:iluuu1994/symfony-demo-2.2.3.git');
5456
runPhpCommand([$dir . '/bin/console', 'cache:clear']);
5557
runPhpCommand([$dir . '/bin/console', 'cache:warmup']);
56-
$process = runValgrindPhpCgiCommand(['-T1,1', $dir . '/public/index.php']);
57-
return ['instructions' => extractInstructionsFromValgrindOutput($process->stderr)];
58+
return runValgrindPhpCgiCommand([$dir . '/public/index.php'], cwd: $dir, jit: $jit, warmup: 10);
5859
}
5960

60-
function runWordpress(): array {
61+
function runWordpress(bool $jit): array {
6162
$dir = __DIR__ . '/repos/wordpress-6.2';
6263
cloneRepo($dir, 'git@github.com:iluuu1994/wordpress-6.2.git');
6364

@@ -77,26 +78,35 @@ function runWordpress(): array {
7778

7879
// Warmup
7980
runPhpCommand([$dir . '/index.php'], $dir);
80-
$process = runValgrindPhpCgiCommand(['-T1,1', $dir . '/index.php'], $dir);
81-
return ['instructions' => extractInstructionsFromValgrindOutput($process->stderr)];
81+
return runValgrindPhpCgiCommand([$dir . '/index.php'], cwd: $dir, jit: $jit, warmup: 10);
8282
}
8383

8484
function runPhpCommand(array $args, ?string $cwd = null): ProcessResult {
8585
return runCommand([PHP_BINARY, ...$args], $cwd);
8686
}
8787

88-
function runValgrindPhpCgiCommand(array $args, ?string $cwd = null): ProcessResult {
88+
function runValgrindPhpCgiCommand(
89+
array $args,
90+
?string $cwd = null,
91+
bool $jit = false,
92+
int $warmup = 0,
93+
): array {
8994
global $phpCgi;
90-
return runCommand([
95+
$process = runCommand([
9196
'valgrind',
9297
'--tool=callgrind',
9398
'--dump-instr=yes',
9499
'--callgrind-out-file=/dev/null',
95100
'--',
96101
$phpCgi,
102+
'-T' . ($warmup ? $warmup . ',' : '') . '1',
97103
'-d max_execution_time=0',
104+
'-d opcache.enable=1',
105+
'-d opcache.jit_buffer_size=' . ($jit ? '128M' : '0'),
98106
...$args,
99107
]);
108+
$instructions = extractInstructionsFromValgrindOutput($process->stderr);
109+
return ['instructions' => $instructions];
100110
}
101111

102112
function extractInstructionsFromValgrindOutput(string $output): ?string {

0 commit comments

Comments
 (0)