3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* * Run pinned to specific CPU core: * taskset -c 3 php perf-regex-printable-characters.php */ $regexA = '/[\x{0000}-\x{0020}\x{007F}-\x{009F}"\'>\/=\x{FDD0}-\x{FDEF}' . '\x{FFFE}\x{FFFF}\x{1FFFE}\x{1FFFF}\x{2FFFE}\x{2FFFF}\x{3FFFE}\x{3FFFF}' . '\x{4FFFE}\x{4FFFF}\x{5FFFE}\x{5FFFF}\x{6FFFE}\x{6FFFF}\x{7FFFE}\x{7FFFF}' . '\x{8FFFE}\x{8FFFF}\x{9FFFE}\x{9FFFF}\x{AFFFE}\x{AFFFF}\x{BFFFE}\x{BFFFF}' . '\x{CFFFE}\x{CFFFF}\x{DFFFE}\x{DFFFF}\x{EFFFE}\x{EFFFF}\x{FFFFE}\x{FFFFF}' . '\x{10FFFE}\x{10FFFF}]/u'; $regexB = '/[\x{0000}-\x{0020}\x{007F}-\x{009F}"\'>\/=\x{FDD0}-\x{FDEF}]' . '|\x{FFFE}|\x{FFFF}|\x{1FFFE}|\x{1FFFF}|\x{2FFFE}|\x{2FFFF}|\x{3FFFE}|\x{3FFFF}' . '|\x{4FFFE}|\x{4FFFF}|\x{5FFFE}|\x{5FFFF}|\x{6FFFE}|\x{6FFFF}|\x{7FFFE}|\x{7FFFF}' . '|\x{8FFFE}|\x{8FFFF}|\x{9FFFE}|\x{9FFFF}|\x{AFFFE}|\x{AFFFF}|\x{BFFFE}|\x{BFFFF}' . '|\x{CFFFE}|\x{CFFFF}|\x{DFFFE}|\x{DFFFF}|\x{EFFFE}|\x{EFFFF}|\x{FFFFE}|\x{FFFFF}' . '|\x{10FFFE}|\x{10FFFF}/u'; $text = 'weengahhoghecho1eeSheeG5el9cie5'; // $text: Interned string - is never flagged IS_STR_VALID_UTF8 $subject = $text . 'b'; // $subject: Gets flagged IS_STR_VALID_UTF8 after very first check - e.g. triggered by `preg_matach('//u', …)` $tests = ['A', 'A', 'B', 'A', 'B', 'A', 'B']; $testRun = 0; foreach ($tests as $test) { $pattern = ''; switch ($test) { case 'A': $pattern = $regexA; break; case 'B': $pattern = $regexB; break; } $start = microtime( true ); for ($i = 0; $i < 1000000; $i++) { preg_match($pattern, $subject); } $diff = sprintf( '%.6f sec.', microtime( true ) - $start ); if ($testRun > 0) { echo "Execution time $test: $diff\n"; } $testRun++; gc_collect_cycles(); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 52
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 52
Branch analysis from position: 9
4 jumps found. (Code = 188) Position 1 = 16, Position 2 = 18, Position 3 = 20, Position 4 = 11
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 26
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 48
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 48
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 26
Branch analysis from position: 31
Branch analysis from position: 26
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 20
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 18
Branch analysis from position: 16
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/VbfOK
function name:  (null)
number of ops:  54
compiled vars:  !0 = $regexA, !1 = $regexB, !2 = $text, !3 = $subject, !4 = $tests, !5 = $testRun, !6 = $test, !7 = $pattern, !8 = $start, !9 = $i, !10 = $diff
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                       !0, '%2F%5B%5Cx%7B0000%7D-%5Cx%7B0020%7D%5Cx%7B007F%7D-%5Cx%7B009F%7D%22%27%3E%5C%2F%3D%5Cx%7BFDD0%7D-%5Cx%7BFDEF%7D%5Cx%7BFFFE%7D%5Cx%7BFFFF%7D%5Cx%7B1FFFE%7D%5Cx%7B1FFFF%7D%5Cx%7B2FFFE%7D%5Cx%7B2FFFF%7D%5Cx%7B3FFFE%7D%5Cx%7B3FFFF%7D%5Cx%7B4FFFE%7D%5Cx%7B4FFFF%7D%5Cx%7B5FFFE%7D%5Cx%7B5FFFF%7D%5Cx%7B6FFFE%7D%5Cx%7B6FFFF%7D%5Cx%7B7FFFE%7D%5Cx%7B7FFFF%7D%5Cx%7B8FFFE%7D%5Cx%7B8FFFF%7D%5Cx%7B9FFFE%7D%5Cx%7B9FFFF%7D%5Cx%7BAFFFE%7D%5Cx%7BAFFFF%7D%5Cx%7BBFFFE%7D%5Cx%7BBFFFF%7D%5Cx%7BCFFFE%7D%5Cx%7BCFFFF%7D%5Cx%7BDFFFE%7D%5Cx%7BDFFFF%7D%5Cx%7BEFFFE%7D%5Cx%7BEFFFF%7D%5Cx%7BFFFFE%7D%5Cx%7BFFFFF%7D%5Cx%7B10FFFE%7D%5Cx%7B10FFFF%7D%5D%2Fu'
   15     1        ASSIGN                                                       !1, '%2F%5B%5Cx%7B0000%7D-%5Cx%7B0020%7D%5Cx%7B007F%7D-%5Cx%7B009F%7D%22%27%3E%5C%2F%3D%5Cx%7BFDD0%7D-%5Cx%7BFDEF%7D%5D%7C%5Cx%7BFFFE%7D%7C%5Cx%7BFFFF%7D%7C%5Cx%7B1FFFE%7D%7C%5Cx%7B1FFFF%7D%7C%5Cx%7B2FFFE%7D%7C%5Cx%7B2FFFF%7D%7C%5Cx%7B3FFFE%7D%7C%5Cx%7B3FFFF%7D%7C%5Cx%7B4FFFE%7D%7C%5Cx%7B4FFFF%7D%7C%5Cx%7B5FFFE%7D%7C%5Cx%7B5FFFF%7D%7C%5Cx%7B6FFFE%7D%7C%5Cx%7B6FFFF%7D%7C%5Cx%7B7FFFE%7D%7C%5Cx%7B7FFFF%7D%7C%5Cx%7B8FFFE%7D%7C%5Cx%7B8FFFF%7D%7C%5Cx%7B9FFFE%7D%7C%5Cx%7B9FFFF%7D%7C%5Cx%7BAFFFE%7D%7C%5Cx%7BAFFFF%7D%7C%5Cx%7BBFFFE%7D%7C%5Cx%7BBFFFF%7D%7C%5Cx%7BCFFFE%7D%7C%5Cx%7BCFFFF%7D%7C%5Cx%7BDFFFE%7D%7C%5Cx%7BDFFFF%7D%7C%5Cx%7BEFFFE%7D%7C%5Cx%7BEFFFF%7D%7C%5Cx%7BFFFFE%7D%7C%5Cx%7BFFFFF%7D%7C%5Cx%7B10FFFE%7D%7C%5Cx%7B10FFFF%7D%2Fu'
   22     2        ASSIGN                                                       !2, 'weengahhoghecho1eeSheeG5el9cie5'
   23     3        CONCAT                                               ~14     !2, 'b'
          4        ASSIGN                                                       !3, ~14
   25     5        ASSIGN                                                       !4, <array>
   27     6        ASSIGN                                                       !5, 0
   28     7      > FE_RESET_R                                           $18     !4, ->52
          8    > > FE_FETCH_R                                                   $18, !6, ->52
   29     9    >   ASSIGN                                                       !7, ''
   30    10      > SWITCH_STRING                                                !6, [ 'A':->16, 'B':->18, ], ->20
   31    11    >   IS_EQUAL                                                     !6, 'A'
         12      > JMPNZ                                                        ~20, ->16
   34    13    >   IS_EQUAL                                                     !6, 'B'
         14      > JMPNZ                                                        ~20, ->18
         15    > > JMP                                                          ->20
   32    16    >   ASSIGN                                                       !7, !0
   33    17      > JMP                                                          ->20
   35    18    >   ASSIGN                                                       !7, !1
   36    19      > JMP                                                          ->20
   39    20    >   INIT_FCALL                                                   'microtime'
         21        SEND_VAL                                                     <true>
         22        DO_ICALL                                             $23     
         23        ASSIGN                                                       !8, $23
   40    24        ASSIGN                                                       !9, 0
         25      > JMP                                                          ->29
   41    26    >   FRAMELESS_ICALL_2                preg_match          ~26     !7, !3
         27        FREE                                                         ~26
   40    28        PRE_INC                                                      !9
         29    >   IS_SMALLER                                                   !9, 1000000
         30      > JMPNZ                                                        ~28, ->26
   43    31    >   INIT_FCALL                                                   'sprintf'
         32        SEND_VAL                                                     '%25.6f+sec.'
         33        INIT_FCALL                                                   'microtime'
         34        SEND_VAL                                                     <true>
         35        DO_ICALL                                             $29     
         36        SUB                                                  ~30     $29, !8
         37        SEND_VAL                                                     ~30
         38        DO_ICALL                                             $31     
         39        ASSIGN                                                       !10, $31
   44    40        IS_SMALLER                                                   0, !5
         41      > JMPZ                                                         ~33, ->48
   45    42    >   ROPE_INIT                                         5  ~35     'Execution+time+'
         43        ROPE_ADD                                          1  ~35     ~35, !6
         44        ROPE_ADD                                          2  ~35     ~35, '%3A+'
         45        ROPE_ADD                                          3  ~35     ~35, !10
         46        ROPE_END                                          4  ~34     ~35, '%0A'
         47        ECHO                                                         ~34
   47    48    >   PRE_INC                                                      !5
   49    49        INIT_FCALL                                                   'gc_collect_cycles'
         50        DO_ICALL                                                     
   28    51      > JMP                                                          ->8
         52    >   FE_FREE                                                      $18
   50    53      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.82 ms | 494 KiB | 12 Q