Passed
Branch master (7fff96)
by Jordan
06:01
created

DecimalArithmeticBench   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 42
dl 0
loc 80
rs 10
c 1
b 0
f 0
wmc 9
1
<?php
2
3
namespace Samsara\Fermat\Bench\Arithmetic;
4
5
use PhpBench\Attributes\BeforeMethods;
6
use PhpBench\Attributes\Groups;
7
use PhpBench\Attributes\ParamProviders;
8
use PhpBench\Attributes\Revs;
9
use Samsara\Fermat\Enums\CalcMode;
10
use Samsara\Fermat\Values\ImmutableDecimal;
11
12
class DecimalArithmeticBench
13
{
14
    public ImmutableDecimal $valueA;
15
    public ImmutableDecimal $valueB;
16
17
    #[Groups(['arithmetic'])]
18
    #[Revs(500)]
19
    #[BeforeMethods('setUp')]
20
    #[ParamProviders(['provideNumbers', 'provideModes'])]
21
    public function benchAddInt()
22
    {
23
        $this->valueA->add($this->valueB);
24
    }
25
26
    #[Groups(['arithmetic'])]
27
    #[Revs(500)]
28
    #[BeforeMethods('setUp')]
29
    #[ParamProviders(['provideNumbers', 'provideModes'])]
30
    public function benchSubtractInt()
31
    {
32
        $this->valueA->subtract($this->valueB);
33
    }
34
35
    #[Groups(['arithmetic'])]
36
    #[Revs(500)]
37
    #[BeforeMethods('setUp')]
38
    #[ParamProviders(['provideNumbers', 'provideModes'])]
39
    public function benchMultiplyInt()
40
    {
41
        $this->valueA->multiply($this->valueB);
42
    }
43
44
    #[Groups(['arithmetic'])]
45
    #[Revs(500)]
46
    #[BeforeMethods('setUp')]
47
    #[ParamProviders(['provideNumbers', 'provideModes'])]
48
    public function benchDivideInt()
49
    {
50
        $this->valueA->divide($this->valueB);
51
    }
52
53
    #[Groups(['arithmetic'])]
54
    #[BeforeMethods('setUp')]
55
    #[ParamProviders(['provideNumbers', 'provideModes'])]
56
    public function benchPowInt()
57
    {
58
        $this->valueA->pow($this->valueB);
59
    }
60
61
    #[Groups(['arithmetic'])]
62
    #[Revs(500)]
63
    #[BeforeMethods('setUp')]
64
    #[ParamProviders(['provideNumbers', 'provideModes'])]
65
    public function benchSqrtInt()
66
    {
67
        $this->valueB->sqrt();
68
    }
69
70
    public function provideNumbers()
71
    {
72
        return [
73
            'int' => ['valueA' => 3, 'valueB' => 2],
74
            'dec' => ['valueA' => '1.5', 'valueB' => '2.6'],
75
            'hard' => ['valueA' => '1.5832947568392048757878954329086890732456748409342578978903245', 'valueB' => '2.65832947568392048757878954329086890732456748409342578978903245'],
76
        ];
77
    }
78
79
    public function provideModes()
80
    {
81
        return [
82
            'auto-mode' => ['mode' => CalcMode::Auto],
83
            'native-mode' => ['mode' => CalcMode::Native],
84
            'precision-mode' => ['mode' => CalcMode::Precision]
85
        ];
86
    }
87
88
    public function setUp(array $params)
89
    {
90
        $this->valueA = (new ImmutableDecimal($params['valueA']))->setMode($params['mode']);
91
        $this->valueB = (new ImmutableDecimal($params['valueB']))->setMode($params['mode']);
92
    }
93
94
}