You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

benchmark.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Benchmarking functions
  4. *
  5. * @package Poweradmin
  6. * @copyright 2007-2010 Rejo Zenger <rejo@zenger.nl>
  7. * @copyright 2010-2014 Poweradmin Development Team
  8. * @license http://opensource.org/licenses/GPL-3.0 GPL
  9. */
  10. $start_memory = memory_get_usage();
  11. $start_time = microtime(true);
  12. /** Get Human Readable Size
  13. *
  14. * Convert size to human readable units
  15. *
  16. * @param int $size Size to convert
  17. *
  18. * @return string $result Human readable size
  19. */
  20. function get_human_readable_usage($size) {
  21. $units = array('B', 'KB', 'MB', 'GB');
  22. $result = $size . ' B';
  23. if ($size < 1024)
  24. return $result;
  25. $index = floor(log($size, 1024));
  26. if ($index < sizeof($units)) {
  27. $result = round($size / pow(1024, ($index)), 2) . ' ' . $units[$index];
  28. }
  29. return $result;
  30. }
  31. /** Print Current Memory and Runtime Stats
  32. */
  33. function display_current_stats() {
  34. global $start_time, $start_memory;
  35. $memory_usage = get_human_readable_usage(memory_get_usage() - $start_memory);
  36. $elapsed_time = sprintf("%.5f", microtime(true) - $start_time);
  37. echo "Memory usage: " . $memory_usage . ", elapsed time: " . $elapsed_time;
  38. }