diff --git a/src/BenchmarkRunner.php b/src/BenchmarkRunner.php index d1d4d44..f353d60 100644 --- a/src/BenchmarkRunner.php +++ b/src/BenchmarkRunner.php @@ -28,6 +28,11 @@ class BenchmarkRunner */ protected $cpus; + /** + * @var int + */ + protected $executions; + /** * @var \React\ChildProcess\Process[] */ @@ -53,12 +58,13 @@ class BenchmarkRunner */ protected $results; - public function __construct(OutputInterface $output, LoopInterface $loop, BenchmarkIterator $benchmarks, $cpus) + public function __construct(OutputInterface $output, LoopInterface $loop, BenchmarkIterator $benchmarks, $cpus, $executions) { $this->output = $output; $this->loop = $loop; $this->benchmarks = $benchmarks; $this->cpus = $cpus; + $this->executions = $executions; } public function run() @@ -83,8 +89,8 @@ protected function calculateResults() { foreach ($this->stdout as $key => $stdout_data) { $stdout_lines = array_filter(explode(PHP_EOL, $stdout_data)); - $memory = array_sum($stdout_lines) / $executions; - $time = array_sum($this->runtimes[$key]) / $executions; + $memory = array_sum($stdout_lines) / $this->executions; + $time = array_sum($this->runtimes[$key]) / $this->executions; $eps = 1 / $time; list($benchmark, $subbenchmark, $count) = unserialize($key); diff --git a/src/RunBenchmarksCommand.php b/src/RunBenchmarksCommand.php index 0994b19..c3f62ea 100644 --- a/src/RunBenchmarksCommand.php +++ b/src/RunBenchmarksCommand.php @@ -125,11 +125,13 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { $output->writeln('No results file found, running benchmarks'); + $executions = $this->getExecutions($input); $runner = new BenchmarkRunner( $output, $this->getLoop(), - $this->getBenchmarkIterator($input), - $this->getCpus($input) + $this->getBenchmarkIterator($input, $executions), + $this->getCpus($input), + $executions ); $runner->run(); $results = $runner->getResults(); @@ -144,13 +146,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Done'); } - protected function getBenchmarkIterator(InputInterface $input) + protected function getBenchmarkIterator(InputInterface $input, $executions) { return new BenchmarkIterator( $this->getBenchmarks($input), ['s', 'a'], $this->getElements($input), - $this->getExecutions($input), + $executions, $this->getPhpPath($input), __DIR__ . '/../benchmarks' );