SHARE
TWEET

Untitled

a guest Mar 8th, 2018 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. const EXECUTION_TIME = 5;
  4.  
  5. // <preparation>
  6. $test = new class
  7. {
  8.     public function exists()
  9.     {
  10.     }
  11. };
  12. // </preparation>
  13.  
  14. $timingStart = microtime(true);
  15. $memoryStart = memory_get_usage(true);
  16. $peakStart   = memory_get_peak_usage(true);
  17.  
  18. for ($iterations = 0; $iterations < PHP_INT_MAX; $iterations++) {
  19.     // <code>
  20.     $test->exists();
  21.     // </code>
  22.  
  23.     // Timing control:
  24.     if ($iterations % 1000 === 0 &&
  25.         microtime(true) - $timingStart >= EXECUTION_TIME) {
  26.         break;
  27.     }
  28. }
  29.  
  30. $timingDuration = microtime(true) - $timingStart;
  31. $memoryEnd      = memory_get_usage(true);
  32. $memoryUsage    = $memoryEnd - $memoryStart;
  33. $peakEnd        = memory_get_peak_usage(true);
  34. $peakUsage      = $peakEnd - $peakStart;
  35.  
  36. echo "\n\n";
  37.  
  38. printf("Cycles count   : %s\n", number_format($iterations, 0, '', '.'));
  39. printf("Cycles by min. : %.2f\n", 60 / $timingDuration * $iterations);
  40. printf("Total time     : %.2f sec.\n", $timingDuration);
  41. printf("Memory usage   : %.2f MB (on end) - %.2f MB (on start) = %.2f MB (delta)\n",
  42.     $memoryEnd / 1048576,
  43.     $memoryStart / 1048576,
  44.     $memoryUsage / 1048576);
  45. printf("Memory peak    : %.2f MB (on end) - %.2f MB (on start) = %.2f MB (delta)\n\n\n",
  46.     $peakEnd / 1048576,
  47.     $peakStart / 1048576,
  48.     $peakUsage / 1048576);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top