benchmark.php 930 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php namespace Laravel;
  2. class Benchmark {
  3. /**
  4. * All of the benchmark starting times.
  5. *
  6. * @var array
  7. */
  8. public static $marks = array();
  9. /**
  10. * Start a benchmark.
  11. *
  12. * After starting a benchmark, the elapsed time in milliseconds can be
  13. * retrieved using the "check" method.
  14. *
  15. * @param string $name
  16. * @return void
  17. */
  18. public static function start($name)
  19. {
  20. static::$marks[$name] = microtime(true);
  21. }
  22. /**
  23. * Get the elapsed time in milliseconds since starting a benchmark.
  24. *
  25. * @param string $name
  26. * @return float
  27. */
  28. public static function check($name)
  29. {
  30. if (array_key_exists($name, static::$marks))
  31. {
  32. return number_format((microtime(true) - static::$marks[$name]) * 1000, 2);
  33. }
  34. return 0.0;
  35. }
  36. /**
  37. * Get the total memory usage in megabytes.
  38. *
  39. * @return float
  40. */
  41. public static function memory()
  42. {
  43. return number_format(memory_get_usage() / 1024 / 1024, 2);
  44. }
  45. }