fork download
  1. <?php
  2.  
  3. function test( $re, $text, $iters ) {
  4. $t1 = microtime( true );
  5. for ( $i=0; $i<$iters; $i++ ) {
  6. $res = preg_match( $re, $text );
  7. };
  8. $t2 = microtime( true );
  9. echo ($t2-$t1).PHP_EOL;
  10. };
  11.  
  12. $re1 = '~"([^"\\\\]|\\\\.)*"~';
  13. $re2 = '~"[^"\\\\]*(\\\\.[^"\\\\]*)*"~';
  14. $text = "\"some text here\"";
  15. $iters = 500000;
  16.  
  17. test( $re1, $text, $iters ); // => ~0.45
  18. test( $re2, $text, $iters ); // => ~0.22
  19.  
Success #stdin #stdout 0.66s 52488KB
stdin
Standard input is empty
stdout
0.44898104667664
0.21313905715942