daily pastebin goal
72%
SHARE
TWEET

Untitled

a guest Sep 7th, 2017 175 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. const EXECUTION_TIME = 60;
  4.  
  5. // <preparation>
  6. $items = range(0, 10);
  7. // </preparation>
  8.  
  9. $timingStart = microtime(true);
  10. $memoryStart = memory_get_usage(true);
  11. $peakStart   = memory_get_peak_usage(true);
  12.  
  13. for ($iterations = 0; $iterations < PHP_INT_MAX; $iterations++) {
  14.     // <code>
  15.     $even = array_filter($items, function ($item) {
  16.         return $item % 2 === 0;
  17.     });
  18.     // </code>
  19.     // Timing control:
  20.     if ($iterations % 1000 === 0 &&
  21.         microtime(true) - $timingStart >= EXECUTION_TIME) {
  22.         break;
  23.     }
  24. }
  25.  
  26. $timingDuration = microtime(true) - $timingStart;
  27. $memoryEnd      = memory_get_usage(true);
  28. $memoryUsage    = $memoryEnd - $memoryStart;
  29. $peakEnd        = memory_get_peak_usage(true);
  30. $peakUsage      = $peakEnd - $peakStart;
  31.  
  32. echo "\n\n";
  33.  
  34. printf("Cycles count   : %.2f\n", $iterations);
  35. printf("Cycles by min. : %.2f\n", 60 / $timingDuration * $iterations);
  36. printf("Total time     : %.2f sec.\n", $timingDuration);
  37. printf("Memory usage   : %.2f MB (on end) - %.2f MB (on start) = %.2f MB (delta)\n",
  38.     $memoryEnd / 1048576,
  39.     $memoryStart / 1048576,
  40.     $memoryUsage / 1048576);
  41. printf("Memory peak    : %.2f MB (on end) - %.2f MB (on start) = %.2f MB (delta)\n\n\n",
  42.     $peakEnd / 1048576,
  43.     $peakStart / 1048576,
  44.     $peakUsage / 1048576);
RAW Paste Data
Top