PHP 27
PHP script render time / execution time By micha on 22nd November 2023 08:45:30 AM
  1. <?php
  2. $enableRenderTime = false;
  3.  
  4. if ($enableRenderTime) {
  5.         $start = microtime(true);
  6.         $startMemory = memory_get_peak_usage();
  7. }
  8. ?>
  9.  
  10. // code to measure
  11.  
  12. <?php
  13. if ($enableRenderTime) {
  14.         $end = microtime(true);
  15.         $endMemory = memory_get_peak_usage();
  16.        
  17.         $executionTime = $end - $start;
  18.         $totalTime = round($executionTime, 4);
  19.        
  20.         $memoryUsage = $endMemory - $startMemory;
  21.         $totalMemory = round($memoryUsage / 1024 / 1024, 4);
  22.  
  23.         echo "<section class='debug rendertime'>";
  24.                 echo "<div class='executionTime'>Script execution time: " . $totalTime . " seconds</div>";
  25.                 echo "<div class='memoryUsage'>Peak memory usage: " . $totalMemory . " mb</div>";
  26.         echo "</section>";
  27. }
  28.  
  29. ?>

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.