3 namespace ZendBench\Cache
;
5 use Zend\Cache\Storage\StorageAdapterInterface
;
8 * @BeforeMethods({"setUp"})
9 * @AfterMethods({"tearDown"})
10 * @BeforeClassMethods({"setUpClass"})
11 * @AfterClassMethods({"tearDownClass"})
13 abstract class CommonStorageAdapterBench
16 * @var StorageAdapterInterface
21 * Key-Value-Pairs of existing items
23 protected $warmItems = [];
26 * Key-Value-Pairs of missing items
28 protected $coldItems = [];
30 public function __construct()
32 // generate warm items
33 for ($i = 0; $i < 10; $i++
) {
34 $this->warmItems
['warm' . $i] = $i;
37 // generate cold items
38 for ($i = 0; $i < 10; $i++
) {
39 $this->coldItems
['cold' . $i] = $i;
43 public function setUp()
45 $this->storage
->setItems($this->warmItems
);
48 public function tearDown()
50 $this->storage
->removeItems(array_keys($this->coldItems
));
53 public static function setUpClass()
57 public static function tearDownClass()
62 * Has missing items with single operations
64 public function benchHasMissingItemsSingle()
66 foreach ($this->coldItems
as $k => $v) {
67 $this->storage
->hasItem($k);
72 * Has missing items at once
74 public function benchHasMissingItemsBulk()
76 $this->storage
->hasItems(array_keys($this->coldItems
));
80 * Has existing items with single operations
82 public function benchHasExistingItemsSingle()
84 foreach ($this->warmItems
as $k => $v) {
85 $this->storage
->hasItem($k);
90 * Has existing items at once
92 public function benchHasExistingItemsBulk()
94 $this->storage
->hasItems(array_keys($this->warmItems
));
98 * Set existing items with single operations
100 public function benchSetExistingItemsSingle()
102 foreach ($this->warmItems
as $k => $v) {
103 $this->storage
->setItem($k, $v);
108 * Set existingn items at once
110 public function benchSetExistingItemsBulk()
112 $this->storage
->setItems($this->warmItems
);
116 * Set missing items with single operations
118 public function benchSetMissingItemsSingle()
120 foreach ($this->coldItems
as $k => $v) {
121 $this->storage
->setItem($k, $k . $v);
126 * Set missing items at once
128 public function benchSetMissingItemsBulk()
130 $this->storage
->setItems($this->coldItems
);
134 * Add items with single operations
136 public function benchAddItemsSingle()
138 foreach ($this->coldItems
as $k => $v) {
139 $this->storage
->addItem($k, $k . $v);
146 public function benchAddItemsBulk()
148 $this->storage
->addItems($this->coldItems
);
152 * Replace items with single operations
154 public function benchReplaceItemsSingle()
156 foreach ($this->warmItems
as $k => $v) {
157 $this->storage
->replaceItem($k, $k . $v);
162 * Replace items at once
164 public function benchReplaceItemsBulk()
166 $this->storage
->replaceItems($this->coldItems
);
170 * Get, check and set items with single operations
172 public function benchGetCheckAndSetItemsSingle()
174 foreach ($this->warmItems
as $k => $v) {
175 $this->storage
->getItem($k, $success, $token);
176 $this->storage
->checkAndSetItem($token, $k, $k . $v);
181 * Touch missing items with single operations
183 public function benchTouchMissingItemsSingle()
185 foreach ($this->coldItems
as $k => $v) {
186 $this->storage
->touchItem($k);
191 * Touch missing items at once
193 public function benchTouchMissingItemsBulk()
195 $this->storage
->touchItems(array_keys($this->coldItems
));
199 * Touch existing items with single operations
201 public function benchTouchExistingItemsSingle()
203 foreach ($this->warmItems
as $k => $v) {
204 $this->storage
->touchItem($k);
209 * Touch existing items at once
211 public function benchTouchExistingItemsBulk()
213 $this->storage
->touchItems(array_keys($this->warmItems
));
217 * Get missing items with single operations
219 public function benchGetMissingItemsSingle()
221 foreach ($this->coldItems
as $k => $v) {
222 $this->storage
->getItem($k);
227 * Get missing items at once
229 public function benchGetMissingItemsBulk()
231 $this->storage
->getItems(array_keys($this->coldItems
));
235 * Get existing items with single operations
237 public function benchGetExistingItemsSingle()
239 foreach ($this->warmItems
as $k => $v) {
240 $this->storage
->getItem($k);
245 * Get existing items at once
247 public function benchGetExistingItemsBulk()
249 $this->storage
->getItems(array_keys($this->warmItems
));
253 * Remove missing items with single operations
255 public function benchRemoveMissingItemsSingle()
257 foreach ($this->coldItems
as $k => $v) {
258 $this->storage
->removeItem($k);
263 * Remove missing items at once
265 public function benchRemoveMissingItemsBulk()
267 $this->storage
->removeItems(array_keys($this->coldItems
));
271 * Remove exisint items with single operations
273 public function benchRemoveExistingItemsSingle()
275 foreach ($this->warmItems
as $k => $v) {
276 $this->storage
->removeItem($k);
281 * Remove existing items at once
283 public function benchRemoveExistingItemsBulk()
285 $this->storage
->removeItems(array_keys($this->warmItems
));
289 * Increment missing items with single operations
291 public function benchIncrementMissingItemsSingle()
293 foreach ($this->coldItems
as $k => $v) {
294 $this->storage
->incrementItem($k, $v);
299 * Increment missing items at once
301 public function benchIncrementMissingItemsBulk()
303 $this->storage
->incrementItems($this->coldItems
);
307 * Increment exisint items with single operations
309 public function benchIncrementExistingItemsSingle()
311 foreach ($this->warmItems
as $k => $v) {
312 $this->storage
->incrementItem($k, $v);
317 * Increment existing items at once
319 public function benchIncrementExistingItemsBulk()
321 $this->storage
->incrementItems($this->warmItems
);
325 * Decrement missing items with single operations
327 public function benchDecrementMissingItemsSingle()
329 foreach ($this->coldItems
as $k => $v) {
330 $this->storage
->decrementItem($k, $v);
335 * Decrement missing items at once
337 public function benchDecrementMissingItemsBulk()
339 $this->storage
->decrementItems($this->coldItems
);
343 * Decrement exisint items with single operations
345 public function benchDecrementExistingItemsSingle()
347 foreach ($this->warmItems
as $k => $v) {
348 $this->storage
->decrementItem($k, $v);
353 * Decrement existing items at once
355 public function benchDecrementExistingItemsBulk()
357 $this->storage
->decrementItems($this->warmItems
);