1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Samsara\Fermat\Values; |
4
|
|
|
|
5
|
|
|
use PhpBench\Attributes\BeforeMethods; |
6
|
|
|
use PhpBench\Attributes\Groups; |
7
|
|
|
use PhpBench\Attributes\ParamProviders; |
8
|
|
|
use PhpBench\Attributes\Revs; |
9
|
|
|
|
10
|
|
|
class DecimalIntBench |
11
|
|
|
{ |
12
|
|
|
public ImmutableDecimal $valueA; |
13
|
|
|
public ImmutableDecimal $valueB; |
14
|
|
|
public ImmutableDecimal $valueC; |
15
|
|
|
|
16
|
|
|
#[Groups(['integer-math', 'revs-test'])] |
17
|
|
|
#[Revs(2000)] |
18
|
|
|
#[BeforeMethods('setUp')] |
19
|
|
|
#[ParamProviders(['provideNumbers', 'provideExtensions'])] |
20
|
|
|
public function benchFactorial() |
21
|
|
|
{ |
22
|
|
|
$this->valueA->factorial(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
#[Groups(['integer-math'])] |
26
|
|
|
#[Revs(500)] |
27
|
|
|
#[BeforeMethods('setUp')] |
28
|
|
|
#[ParamProviders(['provideNumbers', 'provideExtensions'])] |
29
|
|
|
public function benchSubFactorial() |
30
|
|
|
{ |
31
|
|
|
$this->valueA->subFactorial(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
#[Groups(['integer-math'])] |
35
|
|
|
#[BeforeMethods('setUp')] |
36
|
|
|
#[ParamProviders(['provideNumbers', 'provideExtensions'])] |
37
|
|
|
public function benchDoubleFactorial() |
38
|
|
|
{ |
39
|
|
|
$this->valueA->doubleFactorial(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
#[Groups(['integer-math'])] |
43
|
|
|
#[BeforeMethods('setUp')] |
44
|
|
|
#[ParamProviders(['provideNumbers', 'provideExtensions'])] |
45
|
|
|
public function benchSemiFactorial() |
46
|
|
|
{ |
47
|
|
|
$this->valueA->semiFactorial(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
#[Groups(['integer-math'])] |
51
|
|
|
#[Revs(3000)] |
52
|
|
|
#[BeforeMethods('setUp')] |
53
|
|
|
#[ParamProviders(['provideNumbers', 'provideExtensions'])] |
54
|
|
|
public function benchLCM() |
55
|
|
|
{ |
56
|
|
|
$this->valueA->getLeastCommonMultiple($this->valueB); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
#[Groups(['integer-math'])] |
60
|
|
|
#[Revs(1000)] |
61
|
|
|
#[BeforeMethods('setUp')] |
62
|
|
|
#[ParamProviders(['provideNumbers', 'provideExtensions'])] |
63
|
|
|
public function benchGCD() |
64
|
|
|
{ |
65
|
|
|
$this->valueA->getGreatestCommonDivisor($this->valueB); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
#[Groups(['integer-math', 'prime-numbers'])] |
69
|
|
|
#[Revs(100)] |
70
|
|
|
#[BeforeMethods('setUp')] |
71
|
|
|
#[ParamProviders(['provideNumbers', 'provideExtensions'])] |
72
|
|
|
public function benchIsPrime() |
73
|
|
|
{ |
74
|
|
|
$this->valueC->isPrime(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function provideNumbers() |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
'small' => ['valueA' => 6, 'valueB' => 8, 'valueC' => 41], |
81
|
|
|
'medium' => ['valueA' => 16, 'valueB' => 24, 'valueC' => 1009], |
82
|
|
|
'large' => ['valueA' => 160, 'valueB' => 240, 'valueC' => 5915587277], |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function provideExtensions() |
87
|
|
|
{ |
88
|
|
|
return [ |
89
|
|
|
'with-extensions' => ['extensions' => true], |
90
|
|
|
'without-extensions' => ['extensions' => false] |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setUp(array $params) |
95
|
|
|
{ |
96
|
|
|
$this->valueA = (new ImmutableDecimal($params['valueA']))->setExtensions($params['extensions']); |
97
|
|
|
$this->valueB = (new ImmutableDecimal($params['valueB']))->setExtensions($params['extensions']); |
98
|
|
|
$this->valueC = (new ImmutableDecimal($params['valueC']))->setExtensions($params['extensions']); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |