From 738c4edf4a5046f8d14819eafcc7f9611d2cc336 Mon Sep 17 00:00:00 2001 From: davidsteinsland Date: Tue, 3 Dec 2013 00:57:01 +0100 Subject: [PATCH] Closing issue #18 --- src/Athletic/AthleticEvent.php | 37 +++++++++++++++--------- src/Athletic/Results/MethodResults.php | 4 +-- tests/Athletic/TestAsset/RunsCounter.php | 4 +-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Athletic/AthleticEvent.php b/src/Athletic/AthleticEvent.php index 1bea574..84c45a0 100644 --- a/src/Athletic/AthleticEvent.php +++ b/src/Athletic/AthleticEvent.php @@ -28,7 +28,7 @@ public function __construct() } - protected function classSetUp() + protected function classSetUp(array $methods) { } @@ -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) { } @@ -74,7 +83,7 @@ public function run() $methodAnnotations[$methodReflector->getName()] = new Annotations($methodReflector); } - $this->classSetUp(); + $this->classSetUp($methodAnnotations); $results = $this->runBenchmarks($methodAnnotations); $this->classTearDown(); @@ -87,7 +96,7 @@ public function run() * * @return MethodResults[] */ - private function runBenchmarks($methods) + protected function runBenchmarks($methods) { $results = array(); @@ -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); @@ -132,7 +143,7 @@ private function runMethodBenchmark($method, $annotations) * * @return mixed */ - private function timeMethod($method) + protected function timeMethod($method) { $start = microtime(true); $this->$method(); @@ -145,7 +156,7 @@ private function timeMethod($method) * * @return float */ - private function getCalibrationTime($iterations) + protected function getCalibrationTime($iterations) { $emptyCalibrationMethod = 'emptyCalibrationMethod'; $resultsCalibration = array(); @@ -156,7 +167,7 @@ private function getCalibrationTime($iterations) } - private function emptyCalibrationMethod() + protected function emptyCalibrationMethod() { } @@ -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']); @@ -177,4 +188,4 @@ private function setOptionalAnnotations(MethodResults $finalResults, $annotation } } -} \ No newline at end of file +} diff --git a/src/Athletic/Results/MethodResults.php b/src/Athletic/Results/MethodResults.php index 24582c7..7183067 100644 --- a/src/Athletic/Results/MethodResults.php +++ b/src/Athletic/Results/MethodResults.php @@ -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; } @@ -51,4 +51,4 @@ public function setBaseline() { $this->baseline = true; } -} \ No newline at end of file +} diff --git a/tests/Athletic/TestAsset/RunsCounter.php b/tests/Athletic/TestAsset/RunsCounter.php index db92efe..38fc9ea 100644 --- a/tests/Athletic/TestAsset/RunsCounter.php +++ b/tests/Athletic/TestAsset/RunsCounter.php @@ -36,7 +36,7 @@ class RunsCounter extends AthleticEvent /** * {@inheritDoc} */ - public function setUp() + public function setUp($method, $iteration, $iterationCount) { $this->setUps += 1; } @@ -44,7 +44,7 @@ public function setUp() /** * {@inheritDoc} */ - public function tearDown() + public function tearDown($method, $iterationsCount) { $this->tearDowns += 1; }