Skip to content

Commit

Permalink
Closing issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsteinsland committed Dec 2, 2013
1 parent 43fcde8 commit 738c4ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
37 changes: 24 additions & 13 deletions src/Athletic/AthleticEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct()
}


protected function classSetUp()
protected function classSetUp(array $methods)
{

}
Expand All @@ -39,14 +39,23 @@ protected function classTearDown()

}

protected function setUpMethod($method, $iterationsCount)
{

}

protected function tearDownMethod($method, $iterationsCount)
{

}

protected function setUp()
protected function setUp($method, $currentIteration, $iterationsCount)
{

}


protected function tearDown()
protected function tearDown($method, $iterationsCount)
{

}
Expand Down Expand Up @@ -74,7 +83,7 @@ public function run()
$methodAnnotations[$methodReflector->getName()] = new Annotations($methodReflector);
}

$this->classSetUp();
$this->classSetUp($methodAnnotations);
$results = $this->runBenchmarks($methodAnnotations);
$this->classTearDown();

Expand All @@ -87,7 +96,7 @@ public function run()
*
* @return MethodResults[]
*/
private function runBenchmarks($methods)
protected function runBenchmarks($methods)
{
$results = array();

Expand All @@ -106,17 +115,19 @@ private function runBenchmarks($methods)
*
* @return MethodResults
*/
private function runMethodBenchmark($method, $annotations)
protected function runMethodBenchmark($method, $annotations)
{
$iterations = $annotations['iterations'];
$avgCalibration = $this->getCalibrationTime($iterations);

$results = array();
$this->setUpMethod($method, $iterations);
for ($i = 0; $i < $iterations; ++$i) {
$this->setUp();
$this->setUp($method, $i, $iterations);
$results[$i] = $this->timeMethod($method) - $avgCalibration;
$this->tearDown();
$this->tearDown($method, $iterations);
}
$this->tearDownMethod($method, $iterations);

$finalResults = $this->methodResultsFactory->create($method, $results, $iterations);

Expand All @@ -132,7 +143,7 @@ private function runMethodBenchmark($method, $annotations)
*
* @return mixed
*/
private function timeMethod($method)
protected function timeMethod($method)
{
$start = microtime(true);
$this->$method();
Expand All @@ -145,7 +156,7 @@ private function timeMethod($method)
*
* @return float
*/
private function getCalibrationTime($iterations)
protected function getCalibrationTime($iterations)
{
$emptyCalibrationMethod = 'emptyCalibrationMethod';
$resultsCalibration = array();
Expand All @@ -156,7 +167,7 @@ private function getCalibrationTime($iterations)
}


private function emptyCalibrationMethod()
protected function emptyCalibrationMethod()
{

}
Expand All @@ -166,7 +177,7 @@ private function emptyCalibrationMethod()
* @param MethodResults $finalResults
* @param array $annotations
*/
private function setOptionalAnnotations(MethodResults $finalResults, $annotations)
protected function setOptionalAnnotations(MethodResults $finalResults, $annotations)
{
if (isset($annotations['group']) === true) {
$finalResults->setGroup($annotations['group']);
Expand All @@ -177,4 +188,4 @@ private function setOptionalAnnotations(MethodResults $finalResults, $annotation
}
}

}
}
4 changes: 2 additions & 2 deletions src/Athletic/Results/MethodResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($name, $results, $iterations)
$this->avg = ($this->sum / count($results));
$this->max = max($results);
$this->min = min($results);
$this->ops = $iterations / $this->sum;
$this->ops = $this->sum > 0 ? $iterations / $this->sum : 0;
$this->baseline = false;
}

Expand All @@ -51,4 +51,4 @@ public function setBaseline()
{
$this->baseline = true;
}
}
}
4 changes: 2 additions & 2 deletions tests/Athletic/TestAsset/RunsCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class RunsCounter extends AthleticEvent
/**
* {@inheritDoc}
*/
public function setUp()
public function setUp($method, $iteration, $iterationCount)
{
$this->setUps += 1;
}

/**
* {@inheritDoc}
*/
public function tearDown()
public function tearDown($method, $iterationsCount)
{
$this->tearDowns += 1;
}
Expand Down

0 comments on commit 738c4ed

Please sign in to comment.