Last active
February 16, 2020 13:19
-
-
Save ivastly/f9fbed7f289139feed8c3426a6747cd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
/** | |
* @Revs(10000) | |
* @Iterations(3) | |
* @Warmup(1) | |
* @BeforeMethods({"init"}) | |
*/ | |
class LoopConditionalBench | |
{ | |
private $array; | |
private $size; | |
public function init($params): void | |
{ | |
$size = $params['size']; | |
$this->size = $size; | |
$this->array = array_fill(0, $size, 1); | |
} | |
public function provideArraySize(): array | |
{ | |
return [ | |
['size' => 100], | |
['size' => 1000], | |
['size' => 10000], | |
['size' => 100000], | |
['size' => 1000000], | |
]; | |
} | |
/** | |
* @ParamProviders({"provideArraySize"}) | |
*/ | |
public function benchConstantCondition(): void | |
{ | |
for ($i = 0; $i < $this->size; ++$i) | |
{ | |
// intentionally empty | |
} | |
} | |
/** | |
* @ParamProviders({"provideArraySize"}) | |
*/ | |
public function benchCountCallInCondition(): void | |
{ | |
for ($i = 0; $i < count($this->array); ++$i) | |
{ | |
// intentionally empty | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment