Advertisement
Guest User

wisur

a guest
Jun 9th, 2016
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. <?php
  2. /*
  3. ##########################################################################
  4. #                      PHP Benchmark Performance Script                  #
  5. #                         © 2010 Code24 BV                               #
  6. #                                                                        #
  7. #  Author      : Alessandro Torrisi                                      #
  8. #  Company     : Code24 BV, The Netherlands                              #
  9. #  Date        : July 31, 2010                                           #
  10. #  version     : 1.0                                                     #
  11. #  License     : Creative Commons CC-BY license                          #
  12. #  Website     : http://www.php-benchmark-script.com                     #  
  13. #                                                                        #
  14. ##########################################################################
  15. */
  16.  
  17. $multiplier = 1;
  18. if (!empty($_GET['m'])){
  19.     $multiplier = $_GET['m'];
  20. }
  21.  
  22. if ($multiplier > 100){
  23.     die('To high m (Max 100)');
  24. }
  25.  
  26.  
  27.     function test_Loops($count = 4000000) {
  28.         global $multiplier;
  29.         $count = $count * $multiplier;
  30.         $time_start = microtime(true);
  31.         for($i = 0; $i < $count; ++$i);
  32.         $i = 0; while($i < $count) ++$i;
  33.         return number_format(microtime(true) - $time_start, 3);
  34.     }
  35.  
  36.    
  37.     function test_IfElse($count = 2000000) {
  38.         global $multiplier;
  39.         $count = $count * $multiplier;
  40.         $time_start = microtime(true);
  41.         for ($i=0; $i < $count; $i++) {
  42.             if ($i == -1) {
  43.             } elseif ($i == -2) {
  44.             } else if ($i == -3) {
  45.             }
  46.         }
  47.         return number_format(microtime(true) - $time_start, 3);
  48.     }  
  49.  
  50.    
  51.     $total = 0;
  52.     $functions = get_defined_functions();
  53.     $line = str_pad("-",38,"-");
  54.     echo "<pre>$line\n|".str_pad("PHP BENCHMARK SCRIPT",36," ",STR_PAD_BOTH)."|\n$line\nStart : ".date("Y-m-d H:i:s")."\nServer : {$_SERVER['SERVER_NAME']}@{$_SERVER['SERVER_ADDR']}\nPHP version : ".PHP_VERSION."\nPlatform : ".PHP_OS. "\n$line\n";
  55.     foreach ($functions['user'] as $user) {
  56.         if (preg_match('/^test_/', $user)) {
  57.             $total += $result = $user();
  58.             echo str_pad($user, 25) . " : " . $result ." sec.\n";
  59.         }
  60.     }
  61.     echo str_pad("-", 38, "-") . "\n" . str_pad("Total time:", 25) . " : " . $total ." sec.</pre>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement