benchmark.php 855 B

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