Skip to content

Commit 7bccc3e

Browse files
committed
Bench: reuse EnumSet benchmark code for both EnumSet veriants
1 parent 61b680b commit 7bccc3e

File tree

4 files changed

+166
-303
lines changed

4 files changed

+166
-303
lines changed

bench/AbstractEnumSetBench.php

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?php
2+
3+
namespace MabeEnumBench;
4+
5+
use MabeEnum\Enum;
6+
use MabeEnum\EnumSet;
7+
8+
/**
9+
* An abstract benchmark of EnumSet to be used with differrent enumerations.
10+
* (The internal bitset could be both an integer and a binary string)
11+
*
12+
* @BeforeMethods({"init"})
13+
* @Revs(2000)
14+
* @Iterations(25)
15+
*
16+
* @link http://github.com/marc-mabe/php-enum for the canonical source repository
17+
* @copyright Copyright (c) 2017 Marc Bennewitz
18+
* @license http://github.com/marc-mabe/php-enum/blob/master/LICENSE.txt New BSD License
19+
*/
20+
abstract class AbstractEnumSetBench
21+
{
22+
/**
23+
* @var mixed[]
24+
*/
25+
protected $values;
26+
27+
/**
28+
* @var Enum[]
29+
*/
30+
protected $enumerators;
31+
32+
/**
33+
* @var EnumSet
34+
*/
35+
protected $emptySet;
36+
37+
/**
38+
* @var EnumSet
39+
*/
40+
protected $fullSet;
41+
42+
public function benchAttachEnumerator()
43+
{
44+
foreach ($this->enumerators as $enumerator) {
45+
$this->emptySet->attach($enumerator);
46+
}
47+
}
48+
49+
public function benchAttachValue()
50+
{
51+
foreach ($this->values as $value) {
52+
$this->emptySet->attach($value);
53+
}
54+
}
55+
56+
public function benchDetachEnumerator()
57+
{
58+
foreach ($this->enumerators as $enumerator) {
59+
$this->fullSet->detach($enumerator);
60+
}
61+
}
62+
63+
public function benchDetachValue()
64+
{
65+
foreach ($this->values as $value) {
66+
$this->fullSet->detach($value);
67+
}
68+
}
69+
70+
public function benchContainsEnumerator()
71+
{
72+
foreach ($this->enumerators as $enumerator) {
73+
$this->fullSet->contains($enumerator);
74+
}
75+
}
76+
77+
public function benchContainsValue()
78+
{
79+
foreach ($this->values as $value) {
80+
$this->fullSet->contains($value);
81+
}
82+
}
83+
84+
public function benchIterateFull()
85+
{
86+
\iterator_to_array($this->fullSet);
87+
}
88+
89+
public function benchIterateEmpty()
90+
{
91+
\iterator_to_array($this->emptySet);
92+
}
93+
94+
public function benchCountFull()
95+
{
96+
$this->fullSet->count();
97+
}
98+
99+
public function benchCountEmpty()
100+
{
101+
$this->emptySet->count();
102+
}
103+
104+
public function benchIsEqual()
105+
{
106+
$this->fullSet->isEqual($this->fullSet);
107+
}
108+
109+
public function benchIsSubset()
110+
{
111+
$this->fullSet->isEqual($this->fullSet);
112+
}
113+
114+
public function benchIsSuperset()
115+
{
116+
$this->fullSet->isSuperset($this->fullSet);
117+
}
118+
119+
public function benchUnion()
120+
{
121+
$this->fullSet->union($this->emptySet);
122+
}
123+
124+
public function benchIntersect()
125+
{
126+
$this->fullSet->intersect($this->emptySet);
127+
}
128+
129+
public function benchDiff()
130+
{
131+
$this->fullSet->diff($this->emptySet);
132+
}
133+
134+
public function benchSymDiff()
135+
{
136+
$this->fullSet->symDiff($this->emptySet);
137+
}
138+
139+
public function benchGetOrdinalsFull()
140+
{
141+
$this->fullSet->getOrdinals();
142+
}
143+
144+
public function benchGetOrdinalsEmpty()
145+
{
146+
$this->emptySet->getOrdinals();
147+
}
148+
149+
public function benchGetValuesFull()
150+
{
151+
$this->fullSet->getValues();
152+
}
153+
154+
public function benchGetNamesFull()
155+
{
156+
$this->fullSet->getNames();
157+
}
158+
159+
public function benchGetEnumeratorsFull()
160+
{
161+
$this->fullSet->getEnumerators();
162+
}
163+
}

bench/EnumSet32Bench.php

Lines changed: 1 addition & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,12 @@
99
* Benchmark of EnumSet used with an enumeration of 32 enumerators.
1010
* (The internal bitset could be both an integer and a binary string)
1111
*
12-
* @BeforeMethods({"init"})
13-
* @Revs(2000)
14-
* @Iterations(25)
15-
*
1612
* @link http://github.com/marc-mabe/php-enum for the canonical source repository
1713
* @copyright Copyright (c) 2017 Marc Bennewitz
1814
* @license http://github.com/marc-mabe/php-enum/blob/master/LICENSE.txt New BSD License
1915
*/
20-
class EnumSet32Bench
16+
class EnumSet32Bench extends AbstractEnumSetBench
2117
{
22-
/**
23-
* @var mixed[]
24-
*/
25-
private $values;
26-
27-
/**
28-
* @var Enum32[]
29-
*/
30-
private $enumerators;
31-
32-
/**
33-
* @var EnumSet
34-
*/
35-
private $emptySet;
36-
37-
/**
38-
* @var EnumSet
39-
*/
40-
private $fullSet;
41-
4218
/**
4319
* Will be called before every subject
4420
*/
@@ -53,130 +29,4 @@ public function init()
5329
$this->fullSet->attach($enumerator);
5430
}
5531
}
56-
57-
public function benchAttachEnumerator()
58-
{
59-
foreach ($this->enumerators as $enumerator) {
60-
$this->emptySet->attach($enumerator);
61-
}
62-
}
63-
64-
public function benchAttachValue()
65-
{
66-
foreach ($this->values as $value) {
67-
$this->emptySet->attach($value);
68-
}
69-
}
70-
71-
public function benchDetachEnumerator()
72-
{
73-
foreach ($this->enumerators as $enumerator) {
74-
$this->fullSet->detach($enumerator);
75-
}
76-
}
77-
78-
public function benchDetachValue()
79-
{
80-
foreach ($this->values as $value) {
81-
$this->fullSet->detach($value);
82-
}
83-
}
84-
85-
public function benchContainsEnumerator()
86-
{
87-
foreach ($this->enumerators as $enumerator) {
88-
$this->fullSet->contains($enumerator);
89-
}
90-
}
91-
92-
public function benchContainsValue()
93-
{
94-
foreach ($this->values as $value) {
95-
$this->fullSet->contains($value);
96-
}
97-
}
98-
99-
public function benchIterateFull()
100-
{
101-
foreach ($this->fullSet as $enumerator) {
102-
$enumerator->getValue();
103-
}
104-
}
105-
106-
public function benchIterateEmpty()
107-
{
108-
foreach ($this->emptySet as $enumerator) {
109-
$enumerator->getValue();
110-
}
111-
}
112-
113-
public function benchCountFull()
114-
{
115-
$this->fullSet->count();
116-
}
117-
118-
public function benchCountEmpty()
119-
{
120-
$this->emptySet->count();
121-
}
122-
123-
public function benchIsEqual()
124-
{
125-
$this->fullSet->isEqual($this->fullSet);
126-
}
127-
128-
public function benchIsSubset()
129-
{
130-
$this->fullSet->isEqual($this->fullSet);
131-
}
132-
133-
public function benchIsSuperset()
134-
{
135-
$this->fullSet->isSuperset($this->fullSet);
136-
}
137-
138-
public function benchUnion()
139-
{
140-
$this->fullSet->union($this->emptySet);
141-
}
142-
143-
public function benchIntersect()
144-
{
145-
$this->fullSet->intersect($this->emptySet);
146-
}
147-
148-
public function benchDiff()
149-
{
150-
$this->fullSet->diff($this->emptySet);
151-
}
152-
153-
public function benchSymDiff()
154-
{
155-
$this->fullSet->symDiff($this->emptySet);
156-
}
157-
158-
public function benchGetOrdinalsFull()
159-
{
160-
$this->fullSet->getOrdinals();
161-
}
162-
163-
public function benchGetOrdinalsEmpty()
164-
{
165-
$this->emptySet->getOrdinals();
166-
}
167-
168-
public function benchGetValues()
169-
{
170-
$this->fullSet->getValues();
171-
}
172-
173-
public function benchGetNames()
174-
{
175-
$this->fullSet->getNames();
176-
}
177-
178-
public function benchGetEnumerators()
179-
{
180-
$this->fullSet->getEnumerators();
181-
}
18232
}

0 commit comments

Comments
 (0)