Skip to content

Commit c16b321

Browse files
Restore CI Benchmark
1 parent 508b488 commit c16b321

3 files changed

Lines changed: 258 additions & 45 deletions

File tree

.github/benchmark-files/generate_summary.php

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* This script reads benchmark results from the results directory, merges them
77
* into a single directory, and generates a markdown summary with performance
8-
* metrics for different PHP versions, commands, and Xdebug modes.
8+
* metrics for different PHP versions, commands, and Php-Debugger modes.
99
*/
1010

1111
// Create merged directory and copy all result files into it
@@ -67,32 +67,32 @@
6767
// Extract unique values for each dimension
6868
$commands = [];
6969
$phpVersions = [];
70-
$xdebugModes = [];
70+
$phpDebuggerModes = [];
7171

7272
foreach ($matrixValues as $line) {
73-
[$php, $command, $xdebug] = explode(',', $line);
73+
[$php, $command, $phpDebugger] = explode(',', $line);
7474
$phpVersions[$php] = true;
7575
$commands[$command] = true;
76-
$xdebugModes[$xdebug] = true;
76+
$phpDebuggerModes[$phpDebugger] = true;
7777
}
7878

7979
// Sort the arrays
8080
$commands = array_keys($commands);
8181
$phpVersions = array_keys($phpVersions);
82-
$xdebugModes = array_keys($xdebugModes);
82+
$phpDebuggerModes = array_keys($phpDebuggerModes);
8383
sort($commands);
8484
sort($phpVersions);
8585

86-
// Sort xdebug modes according to the defined order, leaving only those which actually exist in the data
87-
$xdebugModeOrder = ["no", "off", "coverage", "debug", "develop", "gcstats", "profile", "trace"];
88-
$xdebugModes = array_values(array_filter($xdebugModeOrder, function($mode) use ($xdebugModes) {
89-
return in_array($mode, $xdebugModes);
86+
// Sort Php-Debugger modes according to the defined order, leaving only those which actually exist in the data
87+
$phpDebuggerModeOrder = ["no", "off", "debug"];
88+
$phpDebuggerModes = array_values(array_filter($phpDebuggerModeOrder, function($mode) use ($phpDebuggerModes) {
89+
return in_array($mode, $phpDebuggerModes);
9090
}));
9191

9292
// Start building the markdown summary and CSV data
9393
$output = "# 🕒 Performance Results\n";
9494
$csvData = [];
95-
$csvData[] = ['command', 'php', 'xdebug_mode', 'instructions', 'slowdown'];
95+
$csvData[] = ['command', 'php', 'php_debugger_mode', 'instructions', 'slowdown'];
9696

9797
// Loop through each command
9898
foreach ($commands as $command) {
@@ -101,21 +101,21 @@
101101
// Loop through each PHP version
102102
foreach ($phpVersions as $php) {
103103
$output .= "\n### **PHP Version:** `$php`\n\n";
104-
$output .= "| Xdebug | Instructions | Slowdown | Δ Instructions |\n";
105-
$output .= "|--------|-------------:|---------:|---------------:|\n";
104+
$output .= "| Php-Debugger | Instructions | Slowdown | Improvement |\n";
105+
$output .= "|--------------|-------------:|---------:|------------:|\n";
106106

107-
// Get base value (when Xdebug mode is "no")
108-
$baseFile = "merged/php-{$php}_cmd-{$command}_xdebug-no.txt";
107+
// Get base value (when Php-Debugger mode is "no")
108+
$baseFile = "merged/php-{$php}_cmd-{$command}_php_debugger-no.txt";
109109
if (!file_exists($baseFile)) {
110110
fwrite(STDERR, "Warning: Base file not found: $baseFile\n");
111111
continue;
112112
}
113113

114114
$baseValue = (int)trim(file_get_contents($baseFile));
115115

116-
// Loop through each Xdebug mode
117-
foreach ($xdebugModes as $xdebug) {
118-
$file = "merged/php-{$php}_cmd-{$command}_xdebug-{$xdebug}.txt";
116+
// Loop through each Php-Debugger mode
117+
foreach ($phpDebuggerModes as $phpDebugger) {
118+
$file = "merged/php-{$php}_cmd-{$command}_php_debugger-{$phpDebugger}.txt";
119119

120120
if (!file_exists($file)) {
121121
continue;
@@ -124,7 +124,7 @@
124124
$value = (int)trim(file_get_contents($file));
125125

126126
// Calculate slowdown
127-
if ($xdebug === 'no') {
127+
if ($phpDebugger === 'no') {
128128
$slowdown = '0%';
129129
$slowdownPercent = 0.0;
130130
} else {
@@ -137,19 +137,18 @@
137137

138138
// Calculate performance change compared to previous results
139139
$performanceChange = '--';
140-
$key = $command . '-' . $php . '-' . $xdebug;
140+
$key = $command . '-' . $php . '-' . $phpDebugger;
141141
if (isset($previousResults[$key])) {
142-
$previousValue = $previousResults[$key];
143-
// Calculate percentage change: (new - old) / old * 100
144-
// Positive means slower (more instructions), negative means faster
145-
$changePercent = (($value - $previousValue) * 100) / $previousValue;
142+
$previousSlowdown = $previousResults[$key];
143+
$currentSlowdown = sprintf('%.1f', $slowdownPercent);
144+
$changePercent = (($previousSlowdown - $currentSlowdown) * 100) / $previousSlowdown;
146145
$performanceChange = sprintf('%+.1f%%', $changePercent);
147146
}
148147

149-
$output .= "| $xdebug | $formattedValue | $slowdown | $performanceChange |\n";
148+
$output .= "| $phpDebugger | $formattedValue | $slowdown | $performanceChange |\n";
150149

151150
// Add to CSV data (with raw numbers, not formatted)
152-
$csvData[] = [$command, $php, $xdebug, $value, sprintf('%.1f', $slowdownPercent)];
151+
$csvData[] = [$command, $php, $phpDebugger, $value, sprintf('%.1f', $slowdownPercent)];
153152
}
154153
}
155154
}
@@ -158,24 +157,24 @@
158157
$output .= "\n# Performance Results Summary\n";
159158
$output .= "\nThese tables show aggregated results across all PHP versions:\n";
160159

161-
// Aggregate data across all PHP versions for each command and xdebug mode
160+
// Aggregate data across all PHP versions for each command and Php-Debugger mode
162161
foreach ($commands as $command) {
163162
$output .= "\n## **Command:** `$command`\n\n";
164-
$output .= "| Xdebug | Slowdown | Δ Instructions |\n";
165-
$output .= "|--------|---------:|---------------:|\n";
163+
$output .= "| Php-Debugger | Slowdown | Improvement |\n";
164+
$output .= "|--------------|---------:|------------:|\n";
166165

167-
// Calculate aggregated values for each xdebug mode
166+
// Calculate aggregated values for each Php-Debugger mode
168167
$aggregatedData = [];
169-
foreach ($xdebugModes as $xdebug) {
168+
foreach ($phpDebuggerModes as $phpDebugger) {
170169
$totalInstructions = 0;
171170
$totalBaseInstructions = 0;
172171
$count = 0;
173172
$totalPerformanceChange = 0;
174173
$performanceChangeCount = 0;
175174

176175
foreach ($phpVersions as $php) {
177-
$file = "merged/php-{$php}_cmd-{$command}_xdebug-{$xdebug}.txt";
178-
$baseFile = "merged/php-{$php}_cmd-{$command}_xdebug-no.txt";
176+
$file = "merged/php-{$php}_cmd-{$command}_php_debugger-{$phpDebugger}.txt";
177+
$baseFile = "merged/php-{$php}_cmd-{$command}_php_debugger-no.txt";
179178

180179
if (file_exists($file) && file_exists($baseFile)) {
181180
$value = (int)trim(file_get_contents($file));
@@ -185,11 +184,14 @@
185184
$totalBaseInstructions += $baseValue;
186185
$count++;
187186

187+
$slowdownPercent = (($value - $baseValue) * 100) / $baseValue;
188+
188189
// Calculate performance change if previous data exists
189-
$key = $command . '-' . $php . '-' . $xdebug;
190+
$key = $command . '-' . $php . '-' . $phpDebugger;
190191
if (isset($previousResults[$key])) {
191-
$previousValue = $previousResults[$key];
192-
$changePercent = (($value - $previousValue) * 100) / $previousValue;
192+
$previousSlowdown = $previousResults[$key];
193+
$currentSlowdown = sprintf('%.1f', $slowdownPercent);
194+
$changePercent = (($previousSlowdown - $currentSlowdown) * 100) / $previousSlowdown;
193195
$totalPerformanceChange += $changePercent;
194196
$performanceChangeCount++;
195197
}
@@ -198,7 +200,7 @@
198200

199201
if ($count > 0) {
200202
// Calculate average slowdown
201-
if ($xdebug === 'no') {
203+
if ($phpDebugger === 'no') {
202204
$avgSlowdown = '0%';
203205
} else {
204206
$avgSlowdownPercent = (($totalInstructions - $totalBaseInstructions) * 100) / $totalBaseInstructions;
@@ -212,7 +214,7 @@
212214
$performanceChange = sprintf('%+.1f%%', $avgPerformanceChange);
213215
}
214216

215-
$output .= "| $xdebug | $avgSlowdown | $performanceChange |\n";
217+
$output .= "| $phpDebugger | $avgSlowdown | $performanceChange |\n";
216218
}
217219
}
218220
}
@@ -278,13 +280,20 @@ function githubApiRequest(string $url): string|false {
278280
/**
279281
* Fetches benchmark results from the latest successful run of the benchmark workflow on the base branch.
280282
*
281-
* @return array Array indexed by "command-php-xdebug" with instruction counts, or empty array if not found
283+
* @return array Array indexed by "command-php-php_debugger" with instruction counts, or empty array if not found
282284
*/
283285
function fetchPreviousBenchmarkResults(): array {
284286
// Determine the base branch for comparison
285-
// For pull requests, use GITHUB_BASE_REF
287+
// If COMPARISON_BRANCH is set, use it explicitly
288+
// Otherwise for pull requests, use GITHUB_BASE_REF
286289
// For other actions, use GITHUB_REF_NAME (current branch)
287-
$baseBranch = getenv('GITHUB_BASE_REF') ?: getenv('GITHUB_REF_NAME');
290+
$comparisonBranch = getenv('COMPARISON_BRANCH');
291+
if ($comparisonBranch !== false && $comparisonBranch !== '') {
292+
$baseBranch = $comparisonBranch;
293+
} else {
294+
$baseBranch = getenv('GITHUB_BASE_REF') ?: getenv('GITHUB_REF_NAME');
295+
}
296+
288297
if (!$baseBranch) {
289298
fwrite(STDERR, "Warning: Could not determine base branch for comparison\n");
290299
return [];
@@ -389,9 +398,9 @@ function fetchPreviousBenchmarkResults(): array {
389398
}
390399

391400
if (count($fields) >= 4) {
392-
// Fields: command, php, xdebug_mode, instructions, slowdown
401+
// Fields: command, php, php_debugger_mode, instructions, slowdown
393402
$key = $fields[0] . '-' . $fields[1] . '-' . $fields[2];
394-
$previousData[$key] = (int)$fields[3];
403+
$previousData[$key] = (int)$fields[4];
395404
}
396405
}
397406

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
zend_extension=xdebug
2-
xdebug.start_with_request=no
1+
zend_extension=php_debugger.so
2+
php_debugger.start_with_request=no
33
; We need this because some of the functions in bench.php do deep recursion and the default nesting level is not enough
4-
xdebug.max_nesting_level=2048
4+
php_debugger.max_nesting_level=2048

0 commit comments

Comments
 (0)