Skip to content

Commit

Permalink
Fixes to execution count in calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
elazar committed Apr 24, 2015
1 parent 1b6c689 commit 0d17488
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/BenchmarkRunner.php
Expand Up @@ -28,6 +28,11 @@ class BenchmarkRunner
*/
protected $cpus;

/**
* @var int
*/
protected $executions;

/**
* @var \React\ChildProcess\Process[]
*/
Expand All @@ -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()
Expand All @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions src/RunBenchmarksCommand.php
Expand Up @@ -125,11 +125,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
$output->writeln('<info>No results file found, running benchmarks</info>');

$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();
Expand All @@ -144,13 +146,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<info>Done</info>');
}

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'
);
Expand Down

0 comments on commit 0d17488

Please sign in to comment.