1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace AlecRabbit\Tools\Traits; |
4
|
|
|
|
5
|
|
|
use AlecRabbit\Accessories\MemoryUsage\MemoryUsageReport; |
6
|
|
|
use AlecRabbit\Tools\Internal\BenchmarkFunction; |
7
|
|
|
use AlecRabbit\Tools\SimpleCounter; |
8
|
|
|
use AlecRabbit\Tools\Timer; |
9
|
|
|
|
10
|
|
|
trait BenchmarkFields |
11
|
|
|
{ |
12
|
|
|
/** @var BenchmarkFunction[] */ |
13
|
|
|
protected $functions = []; |
14
|
|
|
|
15
|
|
|
/** @var MemoryUsageReport */ |
16
|
|
|
protected $memoryUsageReport; |
17
|
|
|
|
18
|
|
|
/** @var int */ |
19
|
|
|
protected $doneIterations = 0; |
20
|
|
|
|
21
|
|
|
/** @var int */ |
22
|
|
|
protected $doneIterationsCombined = 0; |
23
|
|
|
|
24
|
|
|
/** @var Timer */ |
25
|
|
|
protected $timer; |
26
|
|
|
|
27
|
|
|
/** @var SimpleCounter */ |
28
|
|
|
protected $added; |
29
|
|
|
|
30
|
|
|
/** @var SimpleCounter */ |
31
|
|
|
protected $benchmarked; |
32
|
|
|
|
33
|
|
|
/** @var bool */ |
34
|
|
|
protected $showReturns = false; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return BenchmarkFunction[] |
38
|
|
|
*/ |
39
|
16 |
|
public function getFunctions(): array |
40
|
|
|
{ |
41
|
16 |
|
return $this->functions; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return int |
46
|
|
|
*/ |
47
|
16 |
|
public function getDoneIterations(): int |
48
|
|
|
{ |
49
|
16 |
|
return $this->doneIterations; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return Timer |
54
|
|
|
*/ |
55
|
16 |
|
public function getTimer(): Timer |
56
|
|
|
{ |
57
|
16 |
|
return $this->timer; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
16 |
|
public function getDoneIterationsCombined(): int |
64
|
|
|
{ |
65
|
16 |
|
return $this->doneIterationsCombined; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return MemoryUsageReport |
70
|
|
|
*/ |
71
|
16 |
|
public function getMemoryUsageReport(): MemoryUsageReport |
72
|
|
|
{ |
73
|
16 |
|
return $this->memoryUsageReport; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return SimpleCounter |
78
|
|
|
*/ |
79
|
16 |
|
public function getAdded(): SimpleCounter |
80
|
|
|
{ |
81
|
16 |
|
return $this->added; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return SimpleCounter |
86
|
|
|
*/ |
87
|
16 |
|
public function getBenchmarked(): SimpleCounter |
88
|
|
|
{ |
89
|
16 |
|
return $this->benchmarked; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
16 |
|
public function isShowReturns(): bool |
96
|
|
|
{ |
97
|
16 |
|
return $this->showReturns; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
8 |
|
public function isNotShowReturns(): bool |
104
|
|
|
{ |
105
|
8 |
|
return !$this->isShowReturns(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|