Completed
Push — master ( c2654a...8b49d6 )
by Alec
21:15 queued 13:44
created

BenchmarkResult   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 68
ccs 0
cts 23
cp 0
rs 10
c 4
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getRejectionsPercent() 0 3 1
A getMean() 0 3 1
A getDeltaPercent() 0 3 1
A getNumberOfMeasurements() 0 3 1
A getNumberOfRejections() 0 3 1
A __toString() 0 7 1
A __construct() 0 6 1
A getDelta() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools;
4
5
use AlecRabbit\Accessories\Pretty;
6
7
class BenchmarkResult
8
{
9
    /** @var float */
10
    protected $mean;
11
    /** @var float */
12
    protected $delta;
13
    /** @var int */
14
    protected $numberOfMeasurements;
15
    /** @var int */
16
    protected $numberOfRejections;
17
18
    public function __construct(float $mean, float $delta, int $numberOfMeasurements, int $numberOfRejections = 0)
19
    {
20
        $this->mean = $mean;
21
        $this->delta = $delta;
22
        $this->numberOfMeasurements = $numberOfMeasurements;
23
        $this->numberOfRejections = $numberOfRejections;
24
    }
25
26
    public function getDeltaPercent(): float
27
    {
28
        return $this->getDelta() / $this->getMean();
29
    }
30
31
    /**
32
     * @return float
33
     */
34
    public function getDelta(): float
35
    {
36
        return $this->delta;
37
    }
38
39
    /**
40
     * @return float
41
     */
42
    public function getMean(): float
43
    {
44
        return $this->mean;
45
    }
46
47
    public function getRejectionsPercent(): float
48
    {
49
        return $this->getNumberOfRejections() / $this->getNumberOfMeasurements();
50
    }
51
52
    /**
53
     * @return int
54
     */
55
    public function getNumberOfRejections(): int
56
    {
57
        return $this->numberOfRejections;
58
    }
59
60
    /**
61
     * @return int
62
     */
63
    public function getNumberOfMeasurements(): int
64
    {
65
        return $this->numberOfMeasurements;
66
    }
67
68
    public function __toString(): string
69
    {
70
        return
71
            sprintf(
72
                '%s±%s',
73
                Pretty::nanoseconds($this->getMean()),
74
                Pretty::percent($this->getDeltaPercent())
75
            );
76
    }
77
}
78