3v4l.org

run code in 300+ PHP versions simultaneously
<?php $psr4 = array( 'my\\first\\ns\\prefix\\' => 0, 'my\\second\\ns\\prefix\\' => 0, 'my\\third\\ns\prefix' => 0, ); foreach ($psr4 as $prefix => &$v) { $v = strlen($prefix); } $classes = array( 'my\\third\\ns\\prefix\\subns\\class', 'another\\ns\\prefix\\subns\\class', ); echo 'strpos: '; $start = microtime(true); for ($i = 0; $i < 1000; $i++) { foreach ($classes as $class) { foreach ($psr4 as $prefix => $length) { if (0 === strpos($class, $prefix)) { //echo "$class -> $prefix\n"; break; } } } } printf("%F\n", (microtime(true) - $start)); echo "-----------------------------\n"; echo 'strncmp: '; $start = microtime(true); for ($i = 0; $i < 1000; $i++) { foreach ($classes as $class) { foreach ($psr4 as $prefix => $length) { if (!strncmp($class, $prefix, $length)) { //echo "$class -> $prefix\n"; break; } } } } printf("%F\n", (microtime(true) - $start));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 16
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 51
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
2 jumps found. (Code = 77) Position 1 = 52, Position 2 = 67
Branch analysis from position: 52
2 jumps found. (Code = 78) Position 1 = 53, Position 2 = 67
Branch analysis from position: 53
2 jumps found. (Code = 77) Position 1 = 54, Position 2 = 65
Branch analysis from position: 54
2 jumps found. (Code = 78) Position 1 = 55, Position 2 = 65
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 64
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
Branch analysis from position: 65
Branch analysis from position: 65
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 51
Branch analysis from position: 71
Branch analysis from position: 51
Branch analysis from position: 67
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 31
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 31
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 29
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 29
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 29
Branch analysis from position: 29
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 16
Branch analysis from position: 35
Branch analysis from position: 16
Branch analysis from position: 31
Branch analysis from position: 7
filename:       /in/Xpe7t
function name:  (null)
number of ops:  80
compiled vars:  !0 = $psr4, !1 = $v, !2 = $prefix, !3 = $classes, !4 = $start, !5 = $i, !6 = $class, !7 = $length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1      > FE_RESET_RW                                      $9      !0, ->7
          2    > > FE_FETCH_RW                                      ~10     $9, !1, ->7
          3    >   ASSIGN                                                   !2, ~10
    9     4        STRLEN                                           ~12     !2
          5        ASSIGN                                                   !1, ~12
    8     6      > JMP                                                      ->2
          7    >   FE_FREE                                                  $9
   12     8        ASSIGN                                                   !3, <array>
   17     9        ECHO                                                     'strpos%3A+'
   18    10        INIT_FCALL                                               'microtime'
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $15     
         13        ASSIGN                                                   !4, $15
   19    14        ASSIGN                                                   !5, 0
         15      > JMP                                                      ->33
   20    16    > > FE_RESET_R                                       $18     !3, ->31
         17    > > FE_FETCH_R                                               $18, !6, ->31
   21    18    > > FE_RESET_R                                       $19     !0, ->29
         19    > > FE_FETCH_R                                       ~20     $19, !7, ->29
         20    >   ASSIGN                                                   !2, ~20
   22    21        INIT_FCALL                                               'strpos'
         22        SEND_VAR                                                 !6
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $22     
         25        IS_IDENTICAL                                             $22, 0
         26      > JMPZ                                                     ~23, ->28
   24    27    > > JMP                                                      ->29
   21    28    > > JMP                                                      ->19
         29    >   FE_FREE                                                  $19
   20    30      > JMP                                                      ->17
         31    >   FE_FREE                                                  $18
   19    32        PRE_INC                                                  !5
         33    >   IS_SMALLER                                               !5, 1000
         34      > JMPNZ                                                    ~25, ->16
   29    35    >   INIT_FCALL                                               'printf'
         36        SEND_VAL                                                 '%25F%0A'
         37        INIT_FCALL                                               'microtime'
         38        SEND_VAL                                                 <true>
         39        DO_ICALL                                         $26     
         40        SUB                                              ~27     $26, !4
         41        SEND_VAL                                                 ~27
         42        DO_ICALL                                                 
   31    43        ECHO                                                     '-----------------------------%0A'
   33    44        ECHO                                                     'strncmp%3A+'
   34    45        INIT_FCALL                                               'microtime'
         46        SEND_VAL                                                 <true>
         47        DO_ICALL                                         $29     
         48        ASSIGN                                                   !4, $29
   35    49        ASSIGN                                                   !5, 0
         50      > JMP                                                      ->69
   36    51    > > FE_RESET_R                                       $32     !3, ->67
         52    > > FE_FETCH_R                                               $32, !6, ->67
   37    53    > > FE_RESET_R                                       $33     !0, ->65
         54    > > FE_FETCH_R                                       ~34     $33, !7, ->65
         55    >   ASSIGN                                                   !2, ~34
   38    56        INIT_FCALL                                               'strncmp'
         57        SEND_VAR                                                 !6
         58        SEND_VAR                                                 !2
         59        SEND_VAR                                                 !7
         60        DO_ICALL                                         $36     
         61        BOOL_NOT                                         ~37     $36
         62      > JMPZ                                                     ~37, ->64
   40    63    > > JMP                                                      ->65
   37    64    > > JMP                                                      ->54
         65    >   FE_FREE                                                  $33
   36    66      > JMP                                                      ->52
         67    >   FE_FREE                                                  $32
   35    68        PRE_INC                                                  !5
         69    >   IS_SMALLER                                               !5, 1000
         70      > JMPNZ                                                    ~39, ->51
   45    71    >   INIT_FCALL                                               'printf'
         72        SEND_VAL                                                 '%25F%0A'
         73        INIT_FCALL                                               'microtime'
         74        SEND_VAL                                                 <true>
         75        DO_ICALL                                         $40     
         76        SUB                                              ~41     $40, !4
         77        SEND_VAL                                                 ~41
         78        DO_ICALL                                                 
         79      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.99 ms | 1409 KiB | 21 Q