szabivan

Untitled

Sep 12th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. <?php
  2. echo "preg_match (a?)<sup>n</sup>a<sup>n</sup> on a<sup>n</sup>...<br/>";
  3.  
  4. $regex = "";
  5. $haystack = "";
  6.  
  7. ini_set( "pcre.recursion_limit", 100000 );
  8.  
  9. for( $i = 1; $i < 50; $i++ ){
  10.   $regex = "a?".$regex."a";
  11.   $haystack = "a".$haystack;
  12.   $time_start = microtime(true);
  13.   $result = preg_match("/".$regex."/",$haystack);
  14.   $time_end = microtime(true);
  15.   $time = $time_end - $time_start;
  16.   if( $result === FALSE ){
  17.     echo "BULLSHIT! ";
  18.   }
  19.   echo "i = $i: ".number_format($time,5)." seconds, answer: $result<br/>";
  20. }
  21. ?>
Advertisement
Add Comment
Please, Sign In to add comment