1 | <?php |
||
11 | class Aggregation implements AggregationInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $command = ''; |
||
17 | |||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $totalExecutions = 0; |
||
22 | |||
23 | /** |
||
24 | * @var float |
||
25 | */ |
||
26 | private $totalDuration = 0.0; |
||
27 | |||
28 | /** |
||
29 | * @var float |
||
30 | */ |
||
31 | private $minDuration = 0.0; |
||
32 | |||
33 | /** |
||
34 | * @var float |
||
35 | */ |
||
36 | private $maxDuration = 0.0; |
||
37 | |||
38 | /** |
||
39 | * @var float |
||
40 | */ |
||
41 | private $avgDuration = 0.0; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | private $benchmarks = []; |
||
47 | |||
48 | /** |
||
49 | * @param string $command |
||
50 | */ |
||
51 | 1 | public function __construct($command) |
|
55 | |||
56 | /** |
||
57 | * @param BenchmarkInterface $benchmark |
||
58 | */ |
||
59 | 1 | public function aggregate(BenchmarkInterface $benchmark) |
|
60 | { |
||
61 | 1 | $this->totalExecutions += 1; |
|
62 | 1 | $this->totalDuration += (float) $benchmark->getDuration(); |
|
63 | |||
64 | 1 | $this->avgDuration = (float) $this->totalDuration / $this->totalExecutions; |
|
65 | |||
66 | 1 | if ($benchmark->getDuration() > $this->maxDuration) { |
|
67 | 1 | $this->maxDuration = (float) $benchmark->getDuration(); |
|
68 | 1 | } |
|
69 | |||
70 | 1 | if ($benchmark->getDuration() < $this->minDuration || !$this->minDuration) { |
|
71 | 1 | $this->minDuration = (float) $benchmark->getDuration(); |
|
72 | 1 | } |
|
73 | |||
74 | 1 | $this->benchmarks[] = $benchmark; |
|
75 | 1 | } |
|
76 | |||
77 | /** |
||
78 | * @return string |
||
79 | */ |
||
80 | 1 | public function getCommand() |
|
81 | { |
||
82 | 1 | return $this->command; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return BenchmarkInterface[] |
||
87 | */ |
||
88 | 1 | public function getBenchmarks() |
|
92 | |||
93 | /** |
||
94 | * @return int |
||
95 | */ |
||
96 | 1 | public function getTotalExecutions() |
|
100 | |||
101 | /** |
||
102 | * @return float |
||
103 | */ |
||
104 | 1 | public function getTotalDuration() |
|
108 | |||
109 | /** |
||
110 | * @return float |
||
111 | */ |
||
112 | 1 | public function getAvgDuration() |
|
116 | |||
117 | /** |
||
118 | * @return float |
||
119 | */ |
||
120 | 1 | public function getMinDuration() |
|
124 | |||
125 | /** |
||
126 | * @return float |
||
127 | */ |
||
128 | 1 | public function getMaxDuration() |
|
132 | } |
||
133 |