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 */ $regex = '/[\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'; $subjectInterned = 'weengahhoghecho1eeSheeG5el9cie5b'; // Interned string - is never flagged IS_STR_VALID_UTF8 - and thereby needs repeated UTF-8 validation. $text = 'weengahhoghecho1eeSheeG5el9cie5'; $subjectWithFlagValidUtf8 = $text . 'b'; // 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 = $regex; switch ($test) { case 'A': // triggers repeated UTF-8 validation on each run of preg_match $subject = $subjectInterned; break; case 'B': // one-time UTF-8 validation $subject = $subjectWithFlagValidUtf8; 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/u3sWB
function name:  (null)
number of ops:  54
compiled vars:  !0 = $regex, !1 = $subjectInterned, !2 = $text, !3 = $subjectWithFlagValidUtf8, !4 = $tests, !5 = $testRun, !6 = $test, !7 = $pattern, !8 = $subject, !9 = $start, !10 = $i, !11 = $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, 'weengahhoghecho1eeSheeG5el9cie5b'
   17     2        ASSIGN                                                       !2, 'weengahhoghecho1eeSheeG5el9cie5'
   18     3        CONCAT                                               ~15     !2, 'b'
          4        ASSIGN                                                       !3, ~15
   20     5        ASSIGN                                                       !4, <array>
   22     6        ASSIGN                                                       !5, 0
   23     7      > FE_RESET_R                                           $19     !4, ->52
          8    > > FE_FETCH_R                                                   $19, !6, ->52
   24     9    >   ASSIGN                                                       !7, !0
   25    10      > SWITCH_STRING                                                !6, [ 'A':->16, 'B':->18, ], ->20
   26    11    >   IS_EQUAL                                                     !6, 'A'
         12      > JMPNZ                                                        ~21, ->16
   30    13    >   IS_EQUAL                                                     !6, 'B'
         14      > JMPNZ                                                        ~21, ->18
         15    > > JMP                                                          ->20
   28    16    >   ASSIGN                                                       !8, !1
   29    17      > JMP                                                          ->20
   32    18    >   ASSIGN                                                       !8, !3
   33    19      > JMP                                                          ->20
   36    20    >   INIT_FCALL                                                   'microtime'
         21        SEND_VAL                                                     <true>
         22        DO_ICALL                                             $24     
         23        ASSIGN                                                       !9, $24
   37    24        ASSIGN                                                       !10, 0
         25      > JMP                                                          ->29
   38    26    >   FRAMELESS_ICALL_2                preg_match          ~27     !7, !8
         27        FREE                                                         ~27
   37    28        PRE_INC                                                      !10
         29    >   IS_SMALLER                                                   !10, 1000000
         30      > JMPNZ                                                        ~29, ->26
   40    31    >   INIT_FCALL                                                   'sprintf'
         32        SEND_VAL                                                     '%25.6f+sec.'
         33        INIT_FCALL                                                   'microtime'
         34        SEND_VAL                                                     <true>
         35        DO_ICALL                                             $30     
         36        SUB                                                  ~31     $30, !9
         37        SEND_VAL                                                     ~31
         38        DO_ICALL                                             $32     
         39        ASSIGN                                                       !11, $32
   41    40        IS_SMALLER                                                   0, !5
         41      > JMPZ                                                         ~34, ->48
   42    42    >   ROPE_INIT                                         5  ~36     'Execution+time+'
         43        ROPE_ADD                                          1  ~36     ~36, !6
         44        ROPE_ADD                                          2  ~36     ~36, '%3A+'
         45        ROPE_ADD                                          3  ~36     ~36, !11
         46        ROPE_END                                          4  ~35     ~36, '%0A'
         47        ECHO                                                         ~35
   44    48    >   PRE_INC                                                      !5
   46    49        INIT_FCALL                                                   'gc_collect_cycles'
         50        DO_ICALL                                                     
   23    51      > JMP                                                          ->8
         52    >   FE_FREE                                                      $19
   47    53      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
139.63 ms | 494 KiB | 12 Q