-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBenchmarkComparison.php
98 lines (83 loc) · 2.05 KB
/
BenchmarkComparison.php
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
<?php
namespace Alexgaal\Benchmark;
class BenchmarkComparison
{
/**
* @var array
*/
protected $benchmarks = [];
/**
* @var array
*/
protected $comparison = [];
/**
* BenchmarkComparison constructor.
*
* @param array $benchmarks
*
* @throws \Exception
*/
function __construct(array $benchmarks)
{
if (count($benchmarks) === 0 || count($benchmarks) > 2) {
throw new \Exception("Cannot handle more than two Benchmarks.");
}
$this->benchmarks = $benchmarks;
$this->compare();
return $this;
}
/**
* @return BenchmarkComparison
*/
protected function compare()
{
$benchmarks = $this->benchmarks;
$this->comparison = [
'micros' => $benchmarks[0]->getMicros() - $benchmarks[1]->getMicros(),
'millis' => $benchmarks[0]->getMillis() - $benchmarks[1]->getMillis(),
'seconds' => $benchmarks[0]->getSeconds() - $benchmarks[1]->getSeconds(),
'minutes' => $benchmarks[0]->getMinutes() - $benchmarks[1]->getMinutes(),
'factor' => $benchmarks[0]->getMillis() / $benchmarks[1]->getMillis()
];
return $this;
}
/**
* @return float
*/
public function getMicros()
{
return $this->comparison['micros'];
}
/**
* @return float
*/
public function getMillis()
{
return $this->comparison['millis'];
}
/**
* @return float
*/
public function getSeconds()
{
return $this->comparison['seconds'];
}
/**
* @return float
*/
public function getMinutes()
{
return $this->comparison['minutes'];
}
/**
* @return float
*/
public function getFactor()
{
return $this->comparison['factor'];
}
public function __toString()
{
return '<pre>' . print_r($this, true) . '</pre>';
}
}