benchmark.php 855 Bytes
Newer Older
Taylor Otwell committed
1
<?php namespace Laravel;
2 3 4 5

class Benchmark {

	/**
6
	 * All of the benchmark starting times.
7 8 9
	 *
	 * @var array
	 */
Taylor Otwell committed
10
	protected static $marks = array();
11 12

	/**
13
	 * Start a benchmark starting time.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
	 *
	 * @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)
	{
31 32
		if (array_key_exists($name, static::$marks))
		{
Taylor Otwell committed
33
			return (float) number_format((microtime(true) - static::$marks[$name]) * 1000, 2);
34 35
		}

Taylor Otwell committed
36
		return (float) 0.0;
37 38 39 40 41 42 43 44 45
	}

	/**
	 * Get the total memory usage in megabytes.
	 *
	 * @return float
	 */
	public static function memory()
	{
46
		return (float) number_format(memory_get_usage() / 1024 / 1024, 2);
47 48 49
	}

}