3v4l.org

run code in 300+ PHP versions simultaneously
<?php function check($w) { $t = strlen($w); if($t < 5 || $w[0] == '-' || $w[$t-1] == '-' || $w[strpos($w, "-") + 1] == '-') return false; return true; } $a = array ("safety", "safet-", "s-a-fe", "-safet", "s7-45", "s--fs"); $t1 = microtime(true); $c = 0; for ($i = 0; $i < 100000; $i ++ ){ foreach ($a as $w) { if (check($w)) $c ++; //echo $w, PHP_EOL; } } $t2 = microtime(true); echo "time without regex: ", $t2 - $t1, " n=" , $c, PHP_EOL; $t1 = microtime(true); $c = 0; for ($i = 0; $i < 100000; $i ++ ){ foreach ($a as $w) { if (preg_match('/^(?=.{5,6}$)[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$/', $w)) $c ++; //echo $w, PHP_EOL; } } $t2 = microtime(true); echo "time with regex: ", $t2 - $t1, " n=", $c;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 8
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 37
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 46
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 46
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 45
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 45
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 37
Branch analysis from position: 50
Branch analysis from position: 37
Branch analysis from position: 46
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 15
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 8
Branch analysis from position: 20
Branch analysis from position: 8
Branch analysis from position: 16
filename:       /in/BKhD4
function name:  (null)
number of ops:  60
compiled vars:  !0 = $a, !1 = $t1, !2 = $c, !3 = $i, !4 = $w, !5 = $t2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
   15     5        ASSIGN                                                   !2, 0
   16     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->18
   17     8    > > FE_RESET_R                                       $11     !0, ->16
          9    > > FE_FETCH_R                                               $11, !4, ->16
   19    10    >   INIT_FCALL                                               'check'
         11        SEND_VAR                                                 !4
         12        DO_FCALL                                      0  $12     
         13      > JMPZ                                                     $12, ->15
   20    14    >   PRE_INC                                                  !2
   17    15    > > JMP                                                      ->9
         16    >   FE_FREE                                                  $11
   16    17        PRE_INC                                                  !3
         18    >   IS_SMALLER                                               !3, 100000
         19      > JMPNZ                                                    ~15, ->8
   25    20    >   INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $16     
         23        ASSIGN                                                   !5, $16
   27    24        ECHO                                                     'time+without+regex%3A+'
         25        SUB                                              ~18     !5, !1
         26        ECHO                                                     ~18
         27        ECHO                                                     '+n%3D'
         28        ECHO                                                     !2
         29        ECHO                                                     '%0A'
   29    30        INIT_FCALL                                               'microtime'
         31        SEND_VAL                                                 <true>
         32        DO_ICALL                                         $19     
         33        ASSIGN                                                   !1, $19
   31    34        ASSIGN                                                   !2, 0
   32    35        ASSIGN                                                   !3, 0
         36      > JMP                                                      ->48
   33    37    > > FE_RESET_R                                       $23     !0, ->46
         38    > > FE_FETCH_R                                               $23, !4, ->46
   35    39    >   INIT_FCALL                                               'preg_match'
         40        SEND_VAL                                                 '%2F%5E%28%3F%3D.%7B5%2C6%7D%24%29%5Ba-zA-Z0-9%5D%2B%28%3F%3A-%5Ba-zA-Z0-9%5D%2B%29%2A%24%2F'
         41        SEND_VAR                                                 !4
         42        DO_ICALL                                         $24     
         43      > JMPZ                                                     $24, ->45
   36    44    >   PRE_INC                                                  !2
   33    45    > > JMP                                                      ->38
         46    >   FE_FREE                                                  $23
   32    47        PRE_INC                                                  !3
         48    >   IS_SMALLER                                               !3, 100000
         49      > JMPNZ                                                    ~27, ->37
   41    50    >   INIT_FCALL                                               'microtime'
         51        SEND_VAL                                                 <true>
         52        DO_ICALL                                         $28     
         53        ASSIGN                                                   !5, $28
   43    54        ECHO                                                     'time+with+regex%3A+'
         55        SUB                                              ~30     !5, !1
         56        ECHO                                                     ~30
         57        ECHO                                                     '+n%3D'
         58        ECHO                                                     !2
         59      > RETURN                                                   1

Function check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 13
Branch analysis from position: 8
filename:       /in/BKhD4
function name:  check
number of ops:  26
compiled vars:  !0 = $w, !1 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        STRLEN                                           ~2      !0
          2        ASSIGN                                                   !1, ~2
    6     3        IS_SMALLER                                       ~4      !1, 5
          4      > JMPNZ_EX                                         ~4      ~4, ->8
          5    >   FETCH_DIM_R                                      ~5      !0, 0
          6        IS_EQUAL                                         ~6      ~5, '-'
          7        BOOL                                             ~4      ~6
          8    > > JMPNZ_EX                                         ~4      ~4, ->13
          9    >   SUB                                              ~7      !1, 1
         10        FETCH_DIM_R                                      ~8      !0, ~7
         11        IS_EQUAL                                         ~9      ~8, '-'
         12        BOOL                                             ~4      ~9
         13    > > JMPNZ_EX                                         ~4      ~4, ->22
         14    >   INIT_FCALL                                               'strpos'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 '-'
         17        DO_ICALL                                         $10     
         18        ADD                                              ~11     $10, 1
         19        FETCH_DIM_R                                      ~12     !0, ~11
         20        IS_EQUAL                                         ~13     ~12, '-'
         21        BOOL                                             ~4      ~13
         22    > > JMPZ                                                     ~4, ->24
    7    23    > > RETURN                                                   <false>
    8    24    > > RETURN                                                   <true>
    9    25*     > RETURN                                                   null

End of function check

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.24 ms | 1407 KiB | 20 Q