Skip to content

Commit 4a470b3

Browse files
committed
Merged pull request #1029
* pr/1029: Reflow some comments Add comments, add end of file newlines, fix php 8.5 compilation Benchmark Xdebug performance
2 parents a13e487 + 4731ef5 commit 4a470b3

File tree

6 files changed

+614
-0
lines changed

6 files changed

+614
-0
lines changed

.github/benchmark-files/bench.php

Lines changed: 359 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,359 @@
1+
<?php
2+
/**
3+
* This file has been copied from the php-src project. It is just a php process
4+
* that runs some fairly standard algorithms and which serves as an artificial
5+
* benchmark. We removed a couple of functions which were taking long to run
6+
* and which made these benchmarks too slow
7+
*/
8+
if (function_exists("date_default_timezone_set")) {
9+
date_default_timezone_set("UTC");
10+
}
11+
12+
function simple() {
13+
$a = 0;
14+
for ($i = 0; $i < 1000000; $i++)
15+
$a++;
16+
17+
$thisisanotherlongname = 0;
18+
for ($thisisalongname = 0; $thisisalongname < 1000000; $thisisalongname++)
19+
$thisisanotherlongname++;
20+
}
21+
22+
/****/
23+
24+
function simplecall() {
25+
for ($i = 0; $i < 1000000; $i++)
26+
strlen("hallo");
27+
}
28+
29+
/****/
30+
31+
function hallo($a) {
32+
}
33+
34+
function simpleucall() {
35+
for ($i = 0; $i < 1000000; $i++)
36+
hallo("hallo");
37+
}
38+
39+
/****/
40+
41+
function simpleudcall() {
42+
for ($i = 0; $i < 1000000; $i++)
43+
hallo2("hallo");
44+
}
45+
46+
function hallo2($a) {
47+
}
48+
49+
/****/
50+
51+
function Ack($m, $n){
52+
if($m == 0) return $n+1;
53+
if($n == 0) return Ack($m-1, 1);
54+
return Ack($m - 1, Ack($m, ($n - 1)));
55+
}
56+
57+
function ackermann($n) {
58+
$r = Ack(3,$n);
59+
print "Ack(3,$n): $r\n";
60+
}
61+
62+
/****/
63+
64+
function ary($n) {
65+
for ($i=0; $i<$n; $i++) {
66+
$X[$i] = $i;
67+
}
68+
for ($i=$n-1; $i>=0; $i--) {
69+
$Y[$i] = $X[$i];
70+
}
71+
$last = $n-1;
72+
print "$Y[$last]\n";
73+
}
74+
75+
/****/
76+
77+
function ary2($n) {
78+
for ($i=0; $i<$n;) {
79+
$X[$i] = $i; ++$i;
80+
$X[$i] = $i; ++$i;
81+
$X[$i] = $i; ++$i;
82+
$X[$i] = $i; ++$i;
83+
$X[$i] = $i; ++$i;
84+
85+
$X[$i] = $i; ++$i;
86+
$X[$i] = $i; ++$i;
87+
$X[$i] = $i; ++$i;
88+
$X[$i] = $i; ++$i;
89+
$X[$i] = $i; ++$i;
90+
}
91+
for ($i=$n-1; $i>=0;) {
92+
$Y[$i] = $X[$i]; --$i;
93+
$Y[$i] = $X[$i]; --$i;
94+
$Y[$i] = $X[$i]; --$i;
95+
$Y[$i] = $X[$i]; --$i;
96+
$Y[$i] = $X[$i]; --$i;
97+
98+
$Y[$i] = $X[$i]; --$i;
99+
$Y[$i] = $X[$i]; --$i;
100+
$Y[$i] = $X[$i]; --$i;
101+
$Y[$i] = $X[$i]; --$i;
102+
$Y[$i] = $X[$i]; --$i;
103+
}
104+
$last = $n-1;
105+
print "$Y[$last]\n";
106+
}
107+
108+
/****/
109+
110+
function ary3($n) {
111+
for ($i=0; $i<$n; $i++) {
112+
$X[$i] = $i + 1;
113+
$Y[$i] = 0;
114+
}
115+
for ($k=0; $k<1000; $k++) {
116+
for ($i=$n-1; $i>=0; $i--) {
117+
$Y[$i] += $X[$i];
118+
}
119+
}
120+
$last = $n-1;
121+
print "$Y[0] $Y[$last]\n";
122+
}
123+
124+
/****/
125+
126+
/****/
127+
128+
function hash1($n) {
129+
for ($i = 1; $i <= $n; $i++) {
130+
$X[dechex($i)] = $i;
131+
}
132+
$c = 0;
133+
for ($i = $n; $i > 0; $i--) {
134+
if ($X[dechex($i)]) { $c++; }
135+
}
136+
print "$c\n";
137+
}
138+
139+
/****/
140+
141+
function hash2($n) {
142+
for ($i = 0; $i < $n; $i++) {
143+
$hash1["foo_$i"] = $i;
144+
$hash2["foo_$i"] = 0;
145+
}
146+
for ($i = $n; $i > 0; $i--) {
147+
foreach($hash1 as $key => $value) $hash2[$key] += $value;
148+
}
149+
$first = "foo_0";
150+
$last = "foo_".($n-1);
151+
print "$hash1[$first] $hash1[$last] $hash2[$first] $hash2[$last]\n";
152+
}
153+
154+
/****/
155+
156+
function gen_random ($n) {
157+
global $LAST;
158+
return( ($n * ($LAST = ($LAST * IA + IC) % IM)) / IM );
159+
}
160+
161+
function heapsort_r($n, &$ra) {
162+
$l = ($n >> 1) + 1;
163+
$ir = $n;
164+
165+
while (1) {
166+
if ($l > 1) {
167+
$rra = $ra[--$l];
168+
} else {
169+
$rra = $ra[$ir];
170+
$ra[$ir] = $ra[1];
171+
if (--$ir == 1) {
172+
$ra[1] = $rra;
173+
return;
174+
}
175+
}
176+
$i = $l;
177+
$j = $l << 1;
178+
while ($j <= $ir) {
179+
if (($j < $ir) && ($ra[$j] < $ra[$j+1])) {
180+
$j++;
181+
}
182+
if ($rra < $ra[$j]) {
183+
$ra[$i] = $ra[$j];
184+
$j += ($i = $j);
185+
} else {
186+
$j = $ir + 1;
187+
}
188+
}
189+
$ra[$i] = $rra;
190+
}
191+
}
192+
193+
function heapsort($N) {
194+
global $LAST;
195+
196+
define("IM", 139968);
197+
define("IA", 3877);
198+
define("IC", 29573);
199+
200+
$LAST = 42;
201+
for ($i=1; $i<=$N; $i++) {
202+
$ary[$i] = gen_random(1);
203+
}
204+
heapsort_r($N, $ary);
205+
printf("%.10f\n", $ary[$N]);
206+
}
207+
208+
/****/
209+
210+
function mkmatrix ($rows, $cols) {
211+
$count = 1;
212+
$mx = array();
213+
for ($i=0; $i<$rows; $i++) {
214+
for ($j=0; $j<$cols; $j++) {
215+
$mx[$i][$j] = $count++;
216+
}
217+
}
218+
return($mx);
219+
}
220+
221+
function mmult ($rows, $cols, $m1, $m2) {
222+
$m3 = array();
223+
for ($i=0; $i<$rows; $i++) {
224+
for ($j=0; $j<$cols; $j++) {
225+
$x = 0;
226+
for ($k=0; $k<$cols; $k++) {
227+
$x += $m1[$i][$k] * $m2[$k][$j];
228+
}
229+
$m3[$i][$j] = $x;
230+
}
231+
}
232+
return($m3);
233+
}
234+
235+
function matrix($n) {
236+
$SIZE = 30;
237+
$m1 = mkmatrix($SIZE, $SIZE);
238+
$m2 = mkmatrix($SIZE, $SIZE);
239+
while ($n--) {
240+
$mm = mmult($SIZE, $SIZE, $m1, $m2);
241+
}
242+
print "{$mm[0][0]} {$mm[2][3]} {$mm[3][2]} {$mm[4][4]}\n";
243+
}
244+
245+
/****/
246+
247+
function nestedloop($n) {
248+
$x = 0;
249+
for ($a=0; $a<$n; $a++)
250+
for ($b=0; $b<$n; $b++)
251+
for ($c=0; $c<$n; $c++)
252+
for ($d=0; $d<$n; $d++)
253+
for ($e=0; $e<$n; $e++)
254+
for ($f=0; $f<$n; $f++)
255+
$x++;
256+
print "$x\n";
257+
}
258+
259+
/****/
260+
261+
function sieve($n) {
262+
$count = 0;
263+
while ($n-- > 0) {
264+
$count = 0;
265+
$flags = range (0,8192);
266+
for ($i=2; $i<8193; $i++) {
267+
if ($flags[$i] > 0) {
268+
for ($k=$i+$i; $k <= 8192; $k+=$i) {
269+
$flags[$k] = 0;
270+
}
271+
$count++;
272+
}
273+
}
274+
}
275+
print "Count: $count\n";
276+
}
277+
278+
/****/
279+
280+
function strcat($n) {
281+
$str = "";
282+
while ($n-- > 0) {
283+
$str .= "hello\n";
284+
}
285+
$len = strlen($str);
286+
print "$len\n";
287+
}
288+
289+
/*****/
290+
291+
function gethrtime()
292+
{
293+
$hrtime = hrtime();
294+
return (($hrtime[0]*1000000000 + $hrtime[1]) / 1000000000);
295+
}
296+
297+
function start_test()
298+
{
299+
ob_start();
300+
return gethrtime();
301+
}
302+
303+
function end_test($start, $name)
304+
{
305+
global $total;
306+
$end = gethrtime();
307+
ob_end_clean();
308+
$total += $end-$start;
309+
$num = number_format($end-$start,3);
310+
$pad = str_repeat(" ", 24-strlen($name)-strlen($num));
311+
312+
echo $name.$pad.$num."\n";
313+
ob_start();
314+
return gethrtime();
315+
}
316+
317+
function total()
318+
{
319+
global $total;
320+
$pad = str_repeat("-", 24);
321+
echo $pad."\n";
322+
$num = number_format($total,3);
323+
$pad = str_repeat(" ", 24-strlen("Total")-strlen($num));
324+
echo "Total".$pad.$num."\n";
325+
}
326+
327+
$t0 = $t = start_test();
328+
simple();
329+
$t = end_test($t, "simple");
330+
simplecall();
331+
$t = end_test($t, "simplecall");
332+
simpleucall();
333+
$t = end_test($t, "simpleucall");
334+
simpleudcall();
335+
$t = end_test($t, "simpleudcall");
336+
ackermann(7);
337+
$t = end_test($t, "ackermann(7)");
338+
ary(50000);
339+
$t = end_test($t, "ary(50000)");
340+
ary2(50000);
341+
$t = end_test($t, "ary2(50000)");
342+
ary3(2000);
343+
$t = end_test($t, "ary3(2000)");
344+
hash1(50000);
345+
$t = end_test($t, "hash1(50000)");
346+
hash2(500);
347+
$t = end_test($t, "hash2(500)");
348+
heapsort(20000);
349+
$t = end_test($t, "heapsort(20000)");
350+
matrix(20);
351+
$t = end_test($t, "matrix(20)");
352+
nestedloop(12);
353+
$t = end_test($t, "nestedloop(12)");
354+
sieve(30);
355+
$t = end_test($t, "sieve(30)");
356+
strcat(200000);
357+
$t = end_test($t, "strcat(200000)");
358+
total();
359+
?>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Needed so that the php scripts won't time out while being run
2+
max_execution_time=0
3+
; We remove all error handling, printing, and displaying so that it does not
4+
; interfere with the tests
5+
error_reporting=0
6+
display_errors=off
7+
log_errors=off
8+
; We enable the opcache both for cli and cgi modes, disable the jit compiler
9+
; and disable opcache optimization (so that the case where Xdebug is not loaded
10+
; matches the case where it is loaded as Xdebug disables this optimization).
11+
; We also set opcache to use a file cache so that it can be shared between the
12+
; two runs that we do of the Symfony code
13+
opcache.enable=1
14+
opcache.enable_cli=1
15+
opcache.jit=disable
16+
opcache.validate_timestamps=0
17+
opcache.optimization_level=0
18+
opcache.file_cache=/tmp/opcache/
19+
opcache.file_cache_only=1

.github/benchmark-files/rector.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
7+
8+
return RectorConfig::configure()
9+
->withPreparedSets(
10+
rectorPreset: true,
11+
)
12+
->withPaths([
13+
__DIR__ . '/.github/benchmark-files/rector.php',
14+
])
15+
;

0 commit comments

Comments
 (0)