SHARE
TWEET

Matt Parlane

a guest Feb 3rd, 2009 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/local/bin/php
  2. <?php
  3.  
  4.  
  5. ini_set('display_errors', 'on');
  6.  
  7. $method1 = array();
  8.  
  9. $method2 = array();
  10.  
  11. $code = '
  12.         $var1 = "1";
  13.         $var2 = "2";
  14.         if ($var1 == $var2) {
  15.                 $var3 = "3";
  16.         } else {
  17.                 $var = "4";
  18.         }
  19. ';
  20.  
  21. for ($n = 0; $n < 100000; $n++)
  22. {
  23.         // Method 1
  24.  
  25.         $start = microtime(TRUE);
  26.  
  27.         eval($code);
  28.  
  29.         $end = microtime(TRUE);
  30.  
  31.         $method1[] = $end - $start;
  32.  
  33.         // Method 2
  34.  
  35.         $start = microtime(TRUE);
  36.  
  37.         include('data:text/plaintext;base64,'.base64_encode('<?php '.$code));
  38.  
  39.         $end = microtime(TRUE);
  40.  
  41.         $method2[] = $end - $start;
  42. }
  43.  
  44. $total1 = 0;
  45.  
  46. foreach ($method1 as $count1)
  47. {
  48.         $total1 += $count1;
  49. }
  50.  
  51. echo "1 (eval): \n";
  52. echo "Total: {$total1}\n";
  53. echo 'Median: '.$method1[floor(count($method1) / 2)]."\n\n";
  54.  
  55. $total2 = 0;
  56.  
  57. foreach ($method2 as $count2)
  58. {
  59.         $total2 += $count2;
  60. }
  61.  
  62. asort($method2);
  63.  
  64. echo "2 (include): \n";
  65. echo "Total: {$total2}\n";
  66. echo 'Median: '.$method2[floor(count($method2) / 2)]."\n\n";
  67. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top