Skip to content

Commit

Permalink
bug fix in measuring time for every loop
Browse files Browse the repository at this point in the history
added some documentation
  • Loading branch information
Alexander Gaal committed May 4, 2017
1 parent 521c093 commit b8d3ba4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public static function begin()
}

/**
* Measures the running time and used memory of an callback function.
*
* @param $callback
* @param int $loops
* @param bool $avg
Expand All @@ -48,12 +50,11 @@ public static function begin()
*/
public static function time($callback, $loops = 1, $avg = false)
{
$benchmark = new Benchmark();

if (!is_callable($callback)) {
throw new \InvalidArgumentException(__CLASS__ . '::' . __FUNCTION__ . ' requires argument $callback to be callable.');
}

$benchmark = new Benchmark();
$time = 0;
$memory = [
'usage' => 0,
Expand All @@ -78,7 +79,7 @@ public static function time($callback, $loops = 1, $avg = false)

$benchmark->loops[] = [
'memory' => $memory,
'time' => $time
'time' => microtime(true) - $timeLoop
];
}

Expand Down

0 comments on commit b8d3ba4

Please sign in to comment.