Advertisement
Guest User

kek

a guest
Apr 24th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.50 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.1                                                   #
  11. #  License     : Creative Commons CC-BY license                          #
  12. #  Website     : http://www.php-benchmark-script.com                     # 
  13. #                                                                        #
  14. ##########################################################################
  15. */
  16.  
  17. class benchmark {
  18.  
  19.     private static function test_Math($count = 140000) {
  20.         $time_start = microtime(true);
  21.         $mathFunctions = array("abs", "acos", "asin", "atan", "bindec", "floor", "exp", "sin", "tan", "pi", "is_finite", "is_nan", "sqrt");
  22.         foreach ($mathFunctions as $key => $function) {
  23.             if (!function_exists($function)) unset($mathFunctions[$key]);
  24.         }
  25.         for ($i=0; $i < $count; $i++) {
  26.             foreach ($mathFunctions as $function) {
  27.                 $r = call_user_func_array($function, array($i));
  28.             }
  29.         }
  30.         return number_format(microtime(true) - $time_start, 3);
  31.     }
  32.    
  33.    
  34.     private static function test_StringManipulation($count = 130000) {
  35.         $time_start = microtime(true);
  36.         $stringFunctions = array("addslashes", "chunk_split", "metaphone", "strip_tags", "md5", "sha1", "strtoupper", "strtolower", "strrev", "strlen", "soundex", "ord");
  37.         foreach ($stringFunctions as $key => $function) {
  38.             if (!function_exists($function)) unset($stringFunctions[$key]);
  39.         }
  40.         $string = "the quick brown fox jumps over the lazy dog";
  41.         for ($i=0; $i < $count; $i++) {
  42.             foreach ($stringFunctions as $function) {
  43.                 $r = call_user_func_array($function, array($string));
  44.             }
  45.         }
  46.         return number_format(microtime(true) - $time_start, 3);
  47.     }
  48.  
  49.  
  50.     private static function test_Loops($count = 19000000) {
  51.         $time_start = microtime(true);
  52.         for($i = 0; $i < $count; ++$i);
  53.         $i = 0; while($i < $count) ++$i;
  54.         return number_format(microtime(true) - $time_start, 3);
  55.     }
  56.  
  57.    
  58.     private static function test_IfElse($count = 9000000) {
  59.         $time_start = microtime(true);
  60.         for ($i=0; $i < $count; $i++) {
  61.             if ($i == -1) {
  62.             } elseif ($i == -2) {
  63.             } else if ($i == -3) {
  64.             }
  65.         }
  66.         return number_format(microtime(true) - $time_start, 3);
  67.     }  
  68.    
  69.     public static function run ($echo = true) {
  70.         $total = 0;
  71.         $server = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '?') . '@' . (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '?' );
  72.         $methods = get_class_methods('benchmark');
  73.         $line = str_pad("-",38,"-");
  74.         $return = "<pre>$line\n|".str_pad("PHP BENCHMARK SCRIPT",36," ",STR_PAD_BOTH)."|\n$line\nStart : ".date("Y-m-d H:i:s")."\nServer : $server\nPHP version : ".PHP_VERSION."\nPlatform : ".PHP_OS. "\n$line\n";
  75.         foreach ($methods as $method) {
  76.             if (preg_match('/^test_/', $method)) {
  77.                 $total += $result = self::$method();
  78.                 $return .= str_pad($method, 25) . " : " . $result ." sec.\n";
  79.             }
  80.         }
  81.         $return .= str_pad("-", 38, "-") . "\n" . str_pad("Total time:", 25) . " : " . $total ." sec.</pre>";
  82.         if ($echo) echo $return;
  83.         return $return;
  84.     }
  85.  
  86. }
  87.  
  88.  
  89. benchmark::run();
  90.  
  91.    
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement