summaryrefslogtreecommitdiff
path: root/kohana/core/Benchmark.php
diff options
context:
space:
mode:
Diffstat (limited to 'kohana/core/Benchmark.php')
-rw-r--r--kohana/core/Benchmark.php36
1 files changed, 23 insertions, 13 deletions
diff --git a/kohana/core/Benchmark.php b/kohana/core/Benchmark.php
index 5a0111f5..876844f1 100644
--- a/kohana/core/Benchmark.php
+++ b/kohana/core/Benchmark.php
@@ -22,16 +22,18 @@ final class Benchmark {
*/
public static function start($name)
{
- if ( ! isset(self::$marks[$name]))
- {
- self::$marks[$name] = array
+ if ( ! isset(self::$marks[$name])) {
+ self::$marks[$name] = array();
+ }
+
+ array_unshift(self::$marks[$name], array
(
- 'start' => microtime(TRUE),
- 'stop' => FALSE,
+ 'start' => microtime(TRUE),
+ 'stop' => FALSE,
'memory_start' => function_exists('memory_get_usage') ? memory_get_usage() : 0,
'memory_stop' => FALSE
- );
- }
+ )
+ );
}
/**
@@ -42,10 +44,10 @@ final class Benchmark {
*/
public static function stop($name)
{
- if (isset(self::$marks[$name]) AND self::$marks[$name]['stop'] === FALSE)
+ if (isset(self::$marks[$name]) AND self::$marks[$name][0]['stop'] === FALSE)
{
- self::$marks[$name]['stop'] = microtime(TRUE);
- self::$marks[$name]['memory_stop'] = function_exists('memory_get_usage') ? memory_get_usage() : 0;
+ self::$marks[$name][0]['stop'] = microtime(TRUE);
+ self::$marks[$name][0]['memory_stop'] = function_exists('memory_get_usage') ? memory_get_usage() : 0;
}
}
@@ -76,7 +78,7 @@ final class Benchmark {
if ( ! isset(self::$marks[$name]))
return FALSE;
- if (self::$marks[$name]['stop'] === FALSE)
+ if (self::$marks[$name][0]['stop'] === FALSE)
{
// Stop the benchmark to prevent mis-matched results
self::stop($name);
@@ -84,10 +86,18 @@ final class Benchmark {
// Return a string version of the time between the start and stop points
// Properly reading a float requires using number_format or sprintf
+ $time = $memory = 0;
+ for ($i = 0; $i < count(self::$marks[$name]); $i++)
+ {
+ $time += self::$marks[$name][$i]['stop'] - self::$marks[$name][$i]['start'];
+ $memory += self::$marks[$name][$i]['memory_stop'] - self::$marks[$name][$i]['memory_start'];
+ }
+
return array
(
- 'time' => number_format(self::$marks[$name]['stop'] - self::$marks[$name]['start'], $decimals),
- 'memory' => (self::$marks[$name]['memory_stop'] - self::$marks[$name]['memory_start'])
+ 'time' => number_format($time, $decimals),
+ 'memory' => $memory,
+ 'count' => count(self::$marks[$name])
);
}