|
| 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 benchAddEnumerator() |
| 43 | + { |
| 44 | + foreach ($this->enumerators as $enumerator) { |
| 45 | + $this->emptySet->add($enumerator); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + public function benchAddValue() |
| 50 | + { |
| 51 | + foreach ($this->values as $value) { |
| 52 | + $this->emptySet->add($value); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + public function benchWithEnumerator() |
| 57 | + { |
| 58 | + foreach ($this->enumerators as $enumerator) { |
| 59 | + $this->emptySet->with($enumerator); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + public function benchWithValue() |
| 64 | + { |
| 65 | + foreach ($this->values as $value) { |
| 66 | + $this->emptySet->with($value); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + public function benchAddIterableEnumerators() |
| 71 | + { |
| 72 | + $this->emptySet->addIterable($this->enumerators); |
| 73 | + } |
| 74 | + |
| 75 | + public function benchAddIterableValues() |
| 76 | + { |
| 77 | + $this->emptySet->addIterable($this->values); |
| 78 | + } |
| 79 | + |
| 80 | + public function benchWithIterableEnumerators() |
| 81 | + { |
| 82 | + $this->emptySet->withIterable($this->enumerators); |
| 83 | + } |
| 84 | + |
| 85 | + public function benchWithIterableValues() |
| 86 | + { |
| 87 | + $this->emptySet->withIterable($this->values); |
| 88 | + } |
| 89 | + |
| 90 | + public function benchRemoveEnumerator() |
| 91 | + { |
| 92 | + foreach ($this->enumerators as $enumerator) { |
| 93 | + $this->fullSet->remove($enumerator); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + public function benchRemoveValue() |
| 98 | + { |
| 99 | + foreach ($this->values as $value) { |
| 100 | + $this->fullSet->remove($value); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + public function benchWithoutEnumerator() |
| 105 | + { |
| 106 | + foreach ($this->enumerators as $enumerator) { |
| 107 | + $this->fullSet->without($enumerator); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + public function benchWithoutValue() |
| 112 | + { |
| 113 | + foreach ($this->values as $value) { |
| 114 | + $this->fullSet->without($value); |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + public function benchRemoveIterableEnumerators() |
| 119 | + { |
| 120 | + $this->fullSet->removeIterable($this->enumerators); |
| 121 | + } |
| 122 | + |
| 123 | + public function benchRemoveIterableValues() |
| 124 | + { |
| 125 | + $this->fullSet->removeIterable($this->values); |
| 126 | + } |
| 127 | + |
| 128 | + public function benchWithoutIterableEnumerators() |
| 129 | + { |
| 130 | + $this->fullSet->withoutIterable($this->enumerators); |
| 131 | + } |
| 132 | + |
| 133 | + public function benchWithoutIterableValues() |
| 134 | + { |
| 135 | + $this->fullSet->withoutIterable($this->values); |
| 136 | + } |
| 137 | + |
| 138 | + public function benchHasEnumerator() |
| 139 | + { |
| 140 | + foreach ($this->enumerators as $enumerator) { |
| 141 | + $this->fullSet->has($enumerator); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + public function benchHasValue() |
| 146 | + { |
| 147 | + foreach ($this->values as $value) { |
| 148 | + $this->fullSet->has($value); |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + public function benchIterateFull() |
| 153 | + { |
| 154 | + \iterator_to_array($this->fullSet); |
| 155 | + } |
| 156 | + |
| 157 | + public function benchIterateEmpty() |
| 158 | + { |
| 159 | + \iterator_to_array($this->emptySet); |
| 160 | + } |
| 161 | + |
| 162 | + public function benchCountFull() |
| 163 | + { |
| 164 | + $this->fullSet->count(); |
| 165 | + } |
| 166 | + |
| 167 | + public function benchCountEmpty() |
| 168 | + { |
| 169 | + $this->emptySet->count(); |
| 170 | + } |
| 171 | + |
| 172 | + public function benchIsEqual() |
| 173 | + { |
| 174 | + $this->fullSet->isEqual($this->fullSet); |
| 175 | + } |
| 176 | + |
| 177 | + public function benchIsSubset() |
| 178 | + { |
| 179 | + $this->fullSet->isEqual($this->fullSet); |
| 180 | + } |
| 181 | + |
| 182 | + public function benchIsSuperset() |
| 183 | + { |
| 184 | + $this->fullSet->isSuperset($this->fullSet); |
| 185 | + } |
| 186 | + |
| 187 | + public function benchSetUnion() |
| 188 | + { |
| 189 | + $this->fullSet->setUnion($this->emptySet); |
| 190 | + } |
| 191 | + |
| 192 | + public function benchWithUnion() |
| 193 | + { |
| 194 | + $this->fullSet->withUnion($this->emptySet); |
| 195 | + } |
| 196 | + |
| 197 | + public function benchSetIntersect() |
| 198 | + { |
| 199 | + $this->fullSet->setIntersect($this->emptySet); |
| 200 | + } |
| 201 | + |
| 202 | + public function benchWithIntersect() |
| 203 | + { |
| 204 | + $this->fullSet->withIntersect($this->emptySet); |
| 205 | + } |
| 206 | + |
| 207 | + public function benchSetDiff() |
| 208 | + { |
| 209 | + $this->fullSet->setDiff($this->emptySet); |
| 210 | + } |
| 211 | + |
| 212 | + public function benchWithDiff() |
| 213 | + { |
| 214 | + $this->fullSet->withDiff($this->emptySet); |
| 215 | + } |
| 216 | + |
| 217 | + public function benchSetSymDiff() |
| 218 | + { |
| 219 | + $this->fullSet->setSymDiff($this->emptySet); |
| 220 | + } |
| 221 | + |
| 222 | + public function benchWithSymDiff() |
| 223 | + { |
| 224 | + $this->fullSet->withSymDiff($this->emptySet); |
| 225 | + } |
| 226 | + |
| 227 | + public function benchGetOrdinalsFull() |
| 228 | + { |
| 229 | + $this->fullSet->getOrdinals(); |
| 230 | + } |
| 231 | + |
| 232 | + public function benchGetOrdinalsEmpty() |
| 233 | + { |
| 234 | + $this->emptySet->getOrdinals(); |
| 235 | + } |
| 236 | + |
| 237 | + public function benchGetValuesFull() |
| 238 | + { |
| 239 | + $this->fullSet->getValues(); |
| 240 | + } |
| 241 | + |
| 242 | + public function benchGetNamesFull() |
| 243 | + { |
| 244 | + $this->fullSet->getNames(); |
| 245 | + } |
| 246 | + |
| 247 | + public function benchGetEnumeratorsFull() |
| 248 | + { |
| 249 | + $this->fullSet->getEnumerators(); |
| 250 | + } |
| 251 | +} |
0 commit comments