Files
spa-api/laravel/benchmark.php

49 lines
855 B
PHP
Raw Normal View History

2011-08-18 19:56:29 -05:00
<?php namespace Laravel;
2011-06-08 23:45:08 -05:00
class Benchmark {
/**
* All of the benchmark starting times.
2011-06-08 23:45:08 -05:00
*
* @var array
*/
2011-09-04 23:55:28 -05:00
protected static $marks = array();
2011-06-08 23:45:08 -05:00
/**
2011-09-08 17:49:16 -05:00
* Start a benchmark starting time.
2011-06-08 23:45:08 -05:00
*
* @param string $name
* @return void
*/
public static function start($name)
{
static::$marks[$name] = microtime(true);
}
/**
* Get the elapsed time in milliseconds since starting a benchmark.
*
* @param string $name
* @return float
*/
public static function check($name)
{
2011-08-08 08:37:55 -05:00
if (array_key_exists($name, static::$marks))
{
2011-09-04 23:55:28 -05:00
return (float) number_format((microtime(true) - static::$marks[$name]) * 1000, 2);
2011-08-08 08:37:55 -05:00
}
2011-09-04 23:55:28 -05:00
return (float) 0.0;
2011-06-08 23:45:08 -05:00
}
/**
* Get the total memory usage in megabytes.
*
* @return float
*/
public static function memory()
{
2011-09-08 17:49:16 -05:00
return (float) number_format(memory_get_usage() / 1024 / 1024, 2);
2011-06-08 23:45:08 -05:00
}
}