Skip to content

Instantly share code, notes, and snippets.

@ivastly
Last active February 16, 2020 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivastly/f9fbed7f289139feed8c3426a6747cd4 to your computer and use it in GitHub Desktop.
Save ivastly/f9fbed7f289139feed8c3426a6747cd4 to your computer and use it in GitHub Desktop.
<?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