|
5 | 5 | * |
6 | 6 | * This script reads benchmark results from the results directory, merges them |
7 | 7 | * 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. |
9 | 9 | */ |
10 | 10 |
|
11 | 11 | // Create merged directory and copy all result files into it |
|
67 | 67 | // Extract unique values for each dimension |
68 | 68 | $commands = []; |
69 | 69 | $phpVersions = []; |
70 | | -$xdebugModes = []; |
| 70 | +$phpDebuggerModes = []; |
71 | 71 |
|
72 | 72 | foreach ($matrixValues as $line) { |
73 | | - [$php, $command, $xdebug] = explode(',', $line); |
| 73 | + [$php, $command, $phpDebugger] = explode(',', $line); |
74 | 74 | $phpVersions[$php] = true; |
75 | 75 | $commands[$command] = true; |
76 | | - $xdebugModes[$xdebug] = true; |
| 76 | + $phpDebuggerModes[$phpDebugger] = true; |
77 | 77 | } |
78 | 78 |
|
79 | 79 | // Sort the arrays |
80 | 80 | $commands = array_keys($commands); |
81 | 81 | $phpVersions = array_keys($phpVersions); |
82 | | -$xdebugModes = array_keys($xdebugModes); |
| 82 | +$phpDebuggerModes = array_keys($phpDebuggerModes); |
83 | 83 | sort($commands); |
84 | 84 | sort($phpVersions); |
85 | 85 |
|
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); |
90 | 90 | })); |
91 | 91 |
|
92 | 92 | // Start building the markdown summary and CSV data |
93 | 93 | $output = "# 🕒 Performance Results\n"; |
94 | 94 | $csvData = []; |
95 | | -$csvData[] = ['command', 'php', 'xdebug_mode', 'instructions', 'slowdown']; |
| 95 | +$csvData[] = ['command', 'php', 'php_debugger_mode', 'instructions', 'slowdown']; |
96 | 96 |
|
97 | 97 | // Loop through each command |
98 | 98 | foreach ($commands as $command) { |
|
101 | 101 | // Loop through each PHP version |
102 | 102 | foreach ($phpVersions as $php) { |
103 | 103 | $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"; |
106 | 106 |
|
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"; |
109 | 109 | if (!file_exists($baseFile)) { |
110 | 110 | fwrite(STDERR, "Warning: Base file not found: $baseFile\n"); |
111 | 111 | continue; |
112 | 112 | } |
113 | 113 |
|
114 | 114 | $baseValue = (int)trim(file_get_contents($baseFile)); |
115 | 115 |
|
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"; |
119 | 119 |
|
120 | 120 | if (!file_exists($file)) { |
121 | 121 | continue; |
|
124 | 124 | $value = (int)trim(file_get_contents($file)); |
125 | 125 |
|
126 | 126 | // Calculate slowdown |
127 | | - if ($xdebug === 'no') { |
| 127 | + if ($phpDebugger === 'no') { |
128 | 128 | $slowdown = '0%'; |
129 | 129 | $slowdownPercent = 0.0; |
130 | 130 | } else { |
|
137 | 137 |
|
138 | 138 | // Calculate performance change compared to previous results |
139 | 139 | $performanceChange = '--'; |
140 | | - $key = $command . '-' . $php . '-' . $xdebug; |
| 140 | + $key = $command . '-' . $php . '-' . $phpDebugger; |
141 | 141 | 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; |
146 | 145 | $performanceChange = sprintf('%+.1f%%', $changePercent); |
147 | 146 | } |
148 | 147 |
|
149 | | - $output .= "| $xdebug | $formattedValue | $slowdown | $performanceChange |\n"; |
| 148 | + $output .= "| $phpDebugger | $formattedValue | $slowdown | $performanceChange |\n"; |
150 | 149 |
|
151 | 150 | // 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)]; |
153 | 152 | } |
154 | 153 | } |
155 | 154 | } |
|
158 | 157 | $output .= "\n# Performance Results Summary\n"; |
159 | 158 | $output .= "\nThese tables show aggregated results across all PHP versions:\n"; |
160 | 159 |
|
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 |
162 | 161 | foreach ($commands as $command) { |
163 | 162 | $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"; |
166 | 165 |
|
167 | | - // Calculate aggregated values for each xdebug mode |
| 166 | + // Calculate aggregated values for each Php-Debugger mode |
168 | 167 | $aggregatedData = []; |
169 | | - foreach ($xdebugModes as $xdebug) { |
| 168 | + foreach ($phpDebuggerModes as $phpDebugger) { |
170 | 169 | $totalInstructions = 0; |
171 | 170 | $totalBaseInstructions = 0; |
172 | 171 | $count = 0; |
173 | 172 | $totalPerformanceChange = 0; |
174 | 173 | $performanceChangeCount = 0; |
175 | 174 |
|
176 | 175 | 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"; |
179 | 178 |
|
180 | 179 | if (file_exists($file) && file_exists($baseFile)) { |
181 | 180 | $value = (int)trim(file_get_contents($file)); |
|
185 | 184 | $totalBaseInstructions += $baseValue; |
186 | 185 | $count++; |
187 | 186 |
|
| 187 | + $slowdownPercent = (($value - $baseValue) * 100) / $baseValue; |
| 188 | + |
188 | 189 | // Calculate performance change if previous data exists |
189 | | - $key = $command . '-' . $php . '-' . $xdebug; |
| 190 | + $key = $command . '-' . $php . '-' . $phpDebugger; |
190 | 191 | 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; |
193 | 195 | $totalPerformanceChange += $changePercent; |
194 | 196 | $performanceChangeCount++; |
195 | 197 | } |
|
198 | 200 |
|
199 | 201 | if ($count > 0) { |
200 | 202 | // Calculate average slowdown |
201 | | - if ($xdebug === 'no') { |
| 203 | + if ($phpDebugger === 'no') { |
202 | 204 | $avgSlowdown = '0%'; |
203 | 205 | } else { |
204 | 206 | $avgSlowdownPercent = (($totalInstructions - $totalBaseInstructions) * 100) / $totalBaseInstructions; |
|
212 | 214 | $performanceChange = sprintf('%+.1f%%', $avgPerformanceChange); |
213 | 215 | } |
214 | 216 |
|
215 | | - $output .= "| $xdebug | $avgSlowdown | $performanceChange |\n"; |
| 217 | + $output .= "| $phpDebugger | $avgSlowdown | $performanceChange |\n"; |
216 | 218 | } |
217 | 219 | } |
218 | 220 | } |
@@ -278,13 +280,20 @@ function githubApiRequest(string $url): string|false { |
278 | 280 | /** |
279 | 281 | * Fetches benchmark results from the latest successful run of the benchmark workflow on the base branch. |
280 | 282 | * |
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 |
282 | 284 | */ |
283 | 285 | function fetchPreviousBenchmarkResults(): array { |
284 | 286 | // 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 |
286 | 289 | // 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 | + |
288 | 297 | if (!$baseBranch) { |
289 | 298 | fwrite(STDERR, "Warning: Could not determine base branch for comparison\n"); |
290 | 299 | return []; |
@@ -389,9 +398,9 @@ function fetchPreviousBenchmarkResults(): array { |
389 | 398 | } |
390 | 399 |
|
391 | 400 | if (count($fields) >= 4) { |
392 | | - // Fields: command, php, xdebug_mode, instructions, slowdown |
| 401 | + // Fields: command, php, php_debugger_mode, instructions, slowdown |
393 | 402 | $key = $fields[0] . '-' . $fields[1] . '-' . $fields[2]; |
394 | | - $previousData[$key] = (int)$fields[3]; |
| 403 | + $previousData[$key] = (int)$fields[4]; |
395 | 404 | } |
396 | 405 | } |
397 | 406 |
|
|
0 commit comments