Guest User

Matt Parlane

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