1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* GpsLab component. |
5
|
|
|
* |
6
|
|
|
* @author Peter Gribanov <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2017, Peter Gribanov |
8
|
|
|
* @license http://opensource.org/licenses/MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace GpsLab\Component\Enum\Bench\Compare\Operation; |
12
|
|
|
|
13
|
|
|
use GpsLab\Component\Enum\Bench\Compare\CompareEnumBench; |
14
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\AbcExp; |
15
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\AbcRef; |
16
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\DefRef; |
17
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\AbcHappyTypes; |
18
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\AbcMarcMabe; |
19
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\AbcMyClabs; |
20
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\DefMarcMabe; |
21
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\Iterations; |
22
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\Revs; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @Revs(2500) |
26
|
|
|
* @Iterations(25) |
27
|
|
|
*/ |
28
|
|
|
class CompareSelfEnumBench implements CompareEnumBench |
29
|
|
|
{ |
30
|
|
|
public function benchReflectionEnum() |
31
|
|
|
{ |
32
|
|
|
$a = AbcRef::A(); |
33
|
|
|
$a->equals(AbcRef::A()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function benchReflectionEnumNoMagic() |
37
|
|
|
{ |
38
|
|
|
$d = DefRef::byValue(DefRef::D); |
39
|
|
|
$d->equals(DefRef::byValue(DefRef::D)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function benchExplicitEnum() |
43
|
|
|
{ |
44
|
|
|
$a = AbcExp::byValue(AbcExp::A); |
45
|
|
|
$a->equals(AbcExp::byValue(AbcExp::A)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function benchMyCLabsEnum() |
49
|
|
|
{ |
50
|
|
|
$a = AbcMyClabs::A(); |
51
|
|
|
$a->equals(AbcMyClabs::A()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function benchMabeEnum() |
55
|
|
|
{ |
56
|
|
|
$a = AbcMarcMabe::A(); |
57
|
|
|
$a->is(AbcMarcMabe::A()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function benchMabeNoMagicEnum() |
61
|
|
|
{ |
62
|
|
|
$d = DefMarcMabe::byValue(DefMarcMabe::D); |
63
|
|
|
$d->is(DefMarcMabe::byValue(DefMarcMabe::D)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function benchHappyTypesEnum() |
67
|
|
|
{ |
68
|
|
|
$a = AbcHappyTypes::A(); |
69
|
|
|
$a->equals(AbcHappyTypes::A()); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|