php benchmark - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of php benchmark.php

  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.         function test_Math($count = 140000) {
  18.                 $time_start = microtime(true);
  19.                 $mathFunctions = array("abs", "acos", "asin", "atan", "bindec", "floor", "exp", "sin", "tan", "pi", "is_finite", "is_nan", "sqrt");
  20.                 foreach ($mathFunctions as $key => $function) {
  21.                         if (!function_exists($function)) unset($mathFunctions[$key]);
  22.                 }
  23.                 for ($i=0; $i < $count; $i++) {
  24.                         foreach ($mathFunctions as $function) {
  25.                                 $r = call_user_func_array($function, array($i));
  26.                         }
  27.                 }
  28.                 return number_format(microtime(true) - $time_start, 3);
  29.         }
  30.        
  31.        
  32.         function test_StringManipulation($count = 130000) {
  33.                 $time_start = microtime(true);
  34.                 $stringFunctions = array("addslashes", "chunk_split", "metaphone", "strip_tags", "md5", "sha1", "strtoupper", "strtolower", "strrev", "strlen", "soundex", "ord");
  35.                 foreach ($stringFunctions as $key => $function) {
  36.                         if (!function_exists($function)) unset($stringFunctions[$key]);
  37.                 }
  38.                 $string = "the quick brown fox jumps over the lazy dog";
  39.                 for ($i=0; $i < $count; $i++) {
  40.                         foreach ($stringFunctions as $function) {
  41.                                 $r = call_user_func_array($function, array($string));
  42.                         }
  43.                 }
  44.                 return number_format(microtime(true) - $time_start, 3);
  45.         }
  46.  
  47.  
  48.         function test_Loops($count = 19000000) {
  49.                 $time_start = microtime(true);
  50.                 for($i = 0; $i < $count; ++$i);
  51.                 $i = 0; while($i < $count) ++$i;
  52.                 return number_format(microtime(true) - $time_start, 3);
  53.         }
  54.  
  55.        
  56.         function test_IfElse($count = 9000000) {
  57.                 $time_start = microtime(true);
  58.                 for ($i=0; $i < $count; $i++) {
  59.                         if ($i == -1) {
  60.                         } elseif ($i == -2) {
  61.                         } else if ($i == -3) {
  62.                         }
  63.                 }
  64.                 return number_format(microtime(true) - $time_start, 3);
  65.         }      
  66.        
  67.        
  68.         $total = 0;
  69.         $functions = get_defined_functions();
  70.         $line = str_pad("-",38,"-");
  71.         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";
  72.         foreach ($functions['user'] as $user) {
  73.                 if (preg_match('/^test_/', $user)) {
  74.                         $total += $result = $user();
  75.             echo str_pad($user, 25) . " : " . $result ." sec.\n";
  76.         }
  77.         }
  78.         echo str_pad("-", 38, "-") . "\n" . str_pad("Total time:", 25) . " : " . $total ." sec.</pre>";
  79.        
  80. ?>
File Description
  • php benchmark
  • PHP Code
  • 04 Nov-2019
  • 3.09 Kb
You can Share it: