FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
php-src/benchmark/generate_diff.php at master · php/php-src · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
php
/
php-src
Public
Notifications
You must be signed in to change notification settings
Fork
8.1k
Star
40.3k
Code
Issues
960
Pull requests
1k
Actions
Security and quality
52
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
php-src
/
benchmark
/
generate_diff.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
89 lines (79 loc) · 3.17 KB
Breadcrumbs
php-src
/
benchmark
/
generate_diff.php
Copy path
File metadata and controls
89 lines (79 loc) · 3.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require_once
__DIR__
.
'
/shared.php
'
;
function
main
(?
string
$
headCommitHash
, ?
string
$
baseCommitHash
) {
if
(
$
headCommitHash
===
null
||
$
baseCommitHash
===
null
) {
fwrite
(
STDERR
,
"
Usage: php generate_diff.php HEAD_COMMIT_HASH BASE_COMMIT_HASH
\n"
);
exit
(
1
);
}
$
repo
=
__DIR__
.
'
/repos/data
'
;
cloneRepo
(
$
repo
,
'
git@github.com:php/benchmarking-data.git
'
);
$
baseCommitHash
=
find_benchmarked_commit_hash
(
$
repo
,
$
baseCommitHash
);
$
headSummaryFile
=
$
repo
.
'
/
'
.
substr
(
$
headCommitHash
,
0
,
2
) .
'
/
'
.
$
headCommitHash
.
'
/summary.json
'
;
$
baseSummaryFile
=
$
repo
.
'
/
'
.
substr
(
$
baseCommitHash
,
0
,
2
) .
'
/
'
.
$
baseCommitHash
.
'
/summary.json
'
;
if
(!
file_exists
(
$
headSummaryFile
)) {
return
"
Head commit '
$
headCommitHash
' not found
\n"
;
}
if
(!
file_exists
(
$
baseSummaryFile
)) {
return
"
Base commit '
$
baseCommitHash
' not found
\n"
;
}
$
headSummary
=
json_decode
(
file_get_contents
(
$
headSummaryFile
),
true
);
$
baseSummary
=
json_decode
(
file_get_contents
(
$
baseSummaryFile
),
true
);
$
headCommitHashShort
=
substr
(
$
headCommitHash
,
0
,
7
);
$
baseCommitHashShort
=
substr
(
$
baseCommitHash
,
0
,
7
);
$
output
=
"
| Benchmark | Base (
$
baseCommitHashShort
) | Head (
$
headCommitHashShort
) | Diff |
\n"
;
$
output
.=
"
|---|---|---|---|
\n"
;
foreach
(
$
headSummary
as
$
name
=>
$
headBenchmark
) {
if
(
$
name
===
'
branch
'
) {
continue
;
}
$
baseInstructions
=
$
baseSummary
[
$
name
][
'
instructions
'
] ??
null
;
$
headInstructions
=
$
headSummary
[
$
name
][
'
instructions
'
];
$
output
.=
"
|
$
name
|
"
.
formatInstructions
(
$
baseInstructions
) .
"
|
"
.
formatInstructions
(
$
headInstructions
) .
"
|
"
.
formatDiff
(
$
baseInstructions
,
$
headInstructions
) .
"
|
\n"
;
}
return
$
output
;
}
function
formatInstructions
(?
int
$
instructions
):
string
{
if
(
$
instructions
===
null
) {
return
'
-
'
;
}
if
(
$
instructions
>
1e6
) {
return
sprintf
(
'
%.0fM
'
,
$
instructions
/
1e6
);
}
elseif
(
$
instructions
>
1e3
) {
return
sprintf
(
'
%.0fK
'
,
$
instructions
/
1e3
);
}
else
{
return
(
string
)
$
instructions
;
}
}
function
formatDiff
(?
int
$
baseInstructions
,
int
$
headInstructions
):
string
{
if
(
$
baseInstructions
===
null
) {
return
'
-
'
;
}
$
instructionDiff
=
$
headInstructions
-
$
baseInstructions
;
return
sprintf
(
'
%.2f%%
'
,
$
instructionDiff
/
$
baseInstructions
*
100
);
}
function
find_benchmarked_commit_hash
(
string
$
repo
,
string
$
commitHash
): ?
string
{
$
repeat
=
100
;
while
(
true
) {
if
(
$
repeat
-- <=
0
) {
fwrite
(
STDERR
,
"
Count not find benchmarked commit hash
\n"
);
exit
(
1
);
}
$
summaryFile
=
$
repo
.
'
/
'
.
substr
(
$
commitHash
,
0
,
2
) .
'
/
'
.
$
commitHash
.
'
/summary.json
'
;
if
(
file_exists
(
$
summaryFile
)) {
break
;
}
$
commitHash
=
trim
(
runCommand
(
[
'
git
'
,
'
rev-parse
'
,
$
commitHash
.
'
^
'
],
dirname
(
__DIR__
),
printCommand:
false
,
)->
stdout
);
}
return
$
commitHash
;
}
$
headCommitHash
=
$
argv
[
1
] ??
null
;
$
baseCommitHash
=
$
argv
[
2
] ??
null
;
$
output
=
main
(
$
headCommitHash
,
$
baseCommitHash
);
fwrite
(
STDOUT
,
$
output
);
Back
|
FazBrowse Home
|
New Git URL