FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phpbench/lib/Model/Suite.php at program-executor · phpbench/phpbench · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
phpbench
/
phpbench
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
132
Star
2k
Code
Issues
28
Pull requests
10
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
phpbench
/
lib
/
Model
/
Suite.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
332 lines (280 loc) · 8.04 KB
Breadcrumbs
phpbench
/
lib
/
Model
/
Suite.php
Copy path
File metadata and controls
332 lines (280 loc) · 8.04 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<?php
/*
* This file is part of the PHPBench package
*
* (c) Daniel Leech <daniel@dantleech.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace
PhpBench
\
Model
;
use
ArrayIterator
;
use
DateTime
;
use
IteratorAggregate
;
use
PhpBench
\
Assertion
\
VariantAssertionResults
;
use
PhpBench
\
Environment
\
Information
;
use
RuntimeException
;
/**
* Represents a Suite.
*
* This is the base of the object graph created by the Runner.
*
* @implements IteratorAggregate<Benchmark>
*/
class
Suite
implements
IteratorAggregate
{
private
$
tag
;
private
$
date
;
private
$
configPath
;
private
$
envInformations
= [];
/**
* @var Benchmark[]
*/
private
$
benchmarks
= [];
private
$
uuid
;
/**
* __construct.
*
* @param string $tag
* @param string $configPath
* @param Information[] $envInformations
*/
public
function
__construct
(
?
string
$
tag
,
DateTime
$
date
,
?
string
$
configPath
=
null
,
array
$
benchmarks
= [],
array
$
envInformations
= [],
$
uuid
=
null
) {
$
this
->
tag
=
$
tag
?
new
Tag
(
$
tag
) :
null
;
$
this
->
date
=
$
date
;
$
this
->
configPath
=
$
configPath
;
$
this
->
envInformations
=
$
envInformations
;
$
this
->
benchmarks
=
$
benchmarks
;
$
this
->
uuid
=
$
uuid
;
}
/**
* @return array<Benchmark>
*/
public
function
getBenchmarks
():
array
{
return
$
this
->
benchmarks
;
}
public
function
getBenchmark
(
string
$
class
): ?
Benchmark
{
return
$
this
->
benchmarks
[
$
class
] ??
null
;
}
/**
* @param string[] $subjectPatterns
* @param string[] $variantPatterns
*/
public
function
filter
(
array
$
subjectPatterns
,
array
$
variantPatterns
):
self
{
$
new
=
clone
$
this
;
$
benchmarks
=
array_map
(
function
(
Benchmark
$
benchmark
)
use
(
$
subjectPatterns
,
$
variantPatterns
) {
return
$
benchmark
->
filter
(
$
subjectPatterns
,
$
variantPatterns
);
},
$
this
->
benchmarks
);
$
new
->
benchmarks
=
$
benchmarks
;
return
$
new
;
}
/**
* Create and add a benchmark.
*
*/
public
function
createBenchmark
(
string
$
class
):
Benchmark
{
$
benchmark
=
new
Benchmark
(
$
this
,
$
class
);
$
this
->
benchmarks
[
$
class
] =
$
benchmark
;
return
$
benchmark
;
}
public
function
addBenchmark
(
Benchmark
$
benchmark
):
void
{
if
(
$
benchmark
->
getSuite
() !==
$
this
) {
throw
new
RuntimeException
(
'
Adding benchmark to suite to which it does not belong
'
);
}
$
this
->
benchmarks
[
$
benchmark
->
getClass
()] =
$
benchmark
;
}
/**
* @return ArrayIterator<Benchmark>
*/
public
function
getIterator
():
ArrayIterator
{
return
new
ArrayIterator
(
$
this
->
benchmarks
);
}
public
function
getTag
(): ?
Tag
{
return
$
this
->
tag
;
}
public
function
getDate
():
DateTime
{
return
$
this
->
date
;
}
public
function
getConfigPath
(): ?
string
{
return
$
this
->
configPath
;
}
public
function
getSummary
():
Summary
{
return
new
Summary
(
$
this
);
}
public
function
getIterations
():
array
{
$
iterations
= [];
foreach
(
$
this
->
getVariants
()
as
$
variant
) {
foreach
(
$
variant
as
$
iteration
) {
$
iterations
[] =
$
iteration
;
}
}
return
$
iterations
;
}
/**
* @return Subject[]
*/
public
function
getSubjects
():
array
{
$
subjects
= [];
foreach
(
$
this
->
getBenchmarks
()
as
$
benchmark
) {
foreach
(
$
benchmark
->
getSubjects
()
as
$
subject
) {
$
subjects
[] =
$
subject
;
}
}
return
$
subjects
;
}
/**
* @return array<Variant>
*/
public
function
getVariants
():
array
{
$
variants
= [];
foreach
(
$
this
->
getSubjects
()
as
$
subject
) {
foreach
(
$
subject
->
getVariants
()
as
$
variant
) {
$
variants
[] =
$
variant
;
}
}
return
$
variants
;
}
public
function
getErrorStacks
():
array
{
$
errorStacks
= [];
foreach
(
$
this
->
getVariants
()
as
$
variant
) {
if
(
false
===
$
variant
->
hasErrorStack
()) {
continue
;
}
$
errorStacks
[] =
$
variant
->
getErrorStack
();
}
return
$
errorStacks
;
}
/**
* @return VariantAssertionResults[]
*/
public
function
getFailures
():
array
{
$
failures
= [];
/** @var Variant $variant */
foreach
(
$
this
->
getVariants
()
as
$
variant
) {
if
(
0
===
$
variant
->
getAssertionResults
()->
failures
()->
count
()) {
continue
;
}
$
failures
[] =
$
variant
->
getAssertionResults
()->
failures
();
}
return
$
failures
;
}
/**
* @param Information[] $envInformations
*/
public
function
setEnvInformations
(
iterable
$
envInformations
):
void
{
foreach
(
$
envInformations
as
$
envInformation
) {
$
this
->
addEnvInformation
(
$
envInformation
);
}
}
public
function
addEnvInformation
(
Information
$
information
):
void
{
$
this
->
envInformations
[
$
information
->
getName
()] =
$
information
;
}
/**
* @return Information[]
*/
public
function
getEnvInformations
():
array
{
return
$
this
->
envInformations
;
}
/**
* The uuid uniquely identifies this suite.
*
* The uuid is determined by the storage driver, and may be empty
* only when dynamically generating reports on-the-fly.
*
*/
public
function
getUuid
(): ?
string
{
return
$
this
->
uuid
;
}
/**
* Generate a universally unique identifier.
*
* The first 7 characters are the year month and in hex, the rest is a
* truncated sha1 string encoding the environmental information, the
* microtime and the configuration path.
*/
public
function
generateUuid
():
void
{
$
serialized
=
serialize
(
$
this
->
envInformations
);
$
this
->
uuid
=
dechex
((
int
)
$
this
->
getDate
()->
format
(
'
Ymd
'
)) .
substr
(
sha1
(
implode
([
microtime
(),
$
serialized
,
$
this
->
configPath
,
])),
0
, -
7
);
}
public
function
mergeBaselines
(
SuiteCollection
$
suiteCollection
):
self
{
foreach
(
$
suiteCollection
->
getSuites
()
as
$
baselineSuite
) {
foreach
(
$
this
->
getVariants
()
as
$
variant
) {
$
subject
=
$
variant
->
getSubject
();
$
benchmark
=
$
subject
->
getBenchmark
();
$
baselineVariant
=
$
baselineSuite
->
findVariant
(
$
benchmark
->
getClass
(),
$
subject
->
getName
(),
$
variant
->
getParameterSet
()->
getName
()
);
if
(!
$
baselineVariant
) {
continue
;
}
$
variant
->
attachBaseline
(
$
baselineVariant
);
}
}
return
$
this
;
}
public
function
findVariantByParameterSetName
(
string
$
benchmarkClass
,
string
$
subjectName
,
string
$
variantName
): ?
Variant
{
if
(!
$
benchmark
=
$
this
->
getBenchmark
(
$
benchmarkClass
)) {
return
null
;
}
if
(!
$
subject
=
$
benchmark
->
getSubject
(
$
subjectName
)) {
return
null
;
}
return
$
subject
->
getVariant
(
$
variantName
);
}
/**
* @deprecated use findVariantByParameterSetName. will be removed in 2.0
*/
public
function
findVariant
(
string
$
benchmarkClass
,
string
$
subjectName
,
string
$
variantName
): ?
Variant
{
return
$
this
->
findVariantByParameterSetName
(
$
benchmarkClass
,
$
subjectName
,
$
variantName
);
}
public
function
getBaseline
(): ?
self
{
foreach
(
$
this
->
getSubjects
()
as
$
subject
) {
foreach
(
$
subject
->
getVariants
()
as
$
variant
) {
if
(
$
variant
->
getBaseline
()) {
return
$
variant
->
getBaseline
()->
getSubject
()->
getBenchmark
()->
getSuite
();
}
}
}
return
null
;
}
}
Back
|
FazBrowse Home
|
New Git URL