3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = range(0, 99); $start = microtime(1); $result = []; for ($i = 0; $i < 100; $i++) if (preg_match("#$i#", $array[$i])) $result[] = $array[$i]; print "for \$i took ".($start - microtime(1))." seconds\n"; $start = microtime(1); $result = []; for ($i = 0; $i < 100; $i++) if (preg_match("#\d#", $array[$i])) $result[] = $array[$i]; print "for \\d took ".($start - microtime(1))." seconds\n"; $start = microtime(1); $result = []; foreach ($array as $entry) if (preg_match("#\d#", $entry)) $result[] = $entry; print "foreach \\d took ".($start - microtime(1))." seconds\n"; $start = microtime(1); $result = []; $result = preg_grep("#\d#", $array); print "preg_grep \\d took ".($start - microtime(1))." seconds\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 12
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 41
Branch analysis from position: 53
2 jumps found. (Code = 77) Position 1 = 66, Position 2 = 75
Branch analysis from position: 66
2 jumps found. (Code = 78) Position 1 = 67, Position 2 = 75
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 74
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
Branch analysis from position: 74
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 75
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 50
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 41
Branch analysis from position: 53
Branch analysis from position: 41
Branch analysis from position: 50
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 12
Branch analysis from position: 27
Branch analysis from position: 12
Branch analysis from position: 24
filename:       /in/lYuvo
function name:  (null)
number of ops:  101
compiled vars:  !0 = $array, !1 = $start, !2 = $result, !3 = $i, !4 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 99
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !0, $5
    6     5        INIT_FCALL                                               'microtime'
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !1, $7
    7     9        ASSIGN                                                   !2, <array>
    9    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->25
   10    12    >   INIT_FCALL                                               'preg_match'
         13        ROPE_INIT                                     3  ~12     '%23'
         14        ROPE_ADD                                      1  ~12     ~12, !3
         15        ROPE_END                                      2  ~11     ~12, '%23'
         16        SEND_VAL                                                 ~11
         17        FETCH_DIM_R                                      ~14     !0, !3
         18        SEND_VAL                                                 ~14
         19        DO_ICALL                                         $15     
         20      > JMPZ                                                     $15, ->24
   11    21    >   FETCH_DIM_R                                      ~17     !0, !3
         22        ASSIGN_DIM                                               !2
         23        OP_DATA                                                  ~17
    9    24    >   PRE_INC                                                  !3
         25    >   IS_SMALLER                                               !3, 100
         26      > JMPNZ                                                    ~19, ->12
   13    27    >   INIT_FCALL                                               'microtime'
         28        SEND_VAL                                                 1
         29        DO_ICALL                                         $20     
         30        SUB                                              ~21     !1, $20
         31        CONCAT                                           ~22     'for+%24i+took+', ~21
         32        CONCAT                                           ~23     ~22, '+seconds%0A'
         33        ECHO                                                     ~23
   16    34        INIT_FCALL                                               'microtime'
         35        SEND_VAL                                                 1
         36        DO_ICALL                                         $24     
         37        ASSIGN                                                   !1, $24
   17    38        ASSIGN                                                   !2, <array>
   19    39        ASSIGN                                                   !3, 0
         40      > JMP                                                      ->51
   20    41    >   INIT_FCALL                                               'preg_match'
         42        SEND_VAL                                                 '%23%5Cd%23'
         43        FETCH_DIM_R                                      ~28     !0, !3
         44        SEND_VAL                                                 ~28
         45        DO_ICALL                                         $29     
         46      > JMPZ                                                     $29, ->50
   21    47    >   FETCH_DIM_R                                      ~31     !0, !3
         48        ASSIGN_DIM                                               !2
         49        OP_DATA                                                  ~31
   19    50    >   PRE_INC                                                  !3
         51    >   IS_SMALLER                                               !3, 100
         52      > JMPNZ                                                    ~33, ->41
   23    53    >   INIT_FCALL                                               'microtime'
         54        SEND_VAL                                                 1
         55        DO_ICALL                                         $34     
         56        SUB                                              ~35     !1, $34
         57        CONCAT                                           ~36     'for+%5Cd+took+', ~35
         58        CONCAT                                           ~37     ~36, '+seconds%0A'
         59        ECHO                                                     ~37
   26    60        INIT_FCALL                                               'microtime'
         61        SEND_VAL                                                 1
         62        DO_ICALL                                         $38     
         63        ASSIGN                                                   !1, $38
   27    64        ASSIGN                                                   !2, <array>
   29    65      > FE_RESET_R                                       $41     !0, ->75
         66    > > FE_FETCH_R                                               $41, !4, ->75
   30    67    >   INIT_FCALL                                               'preg_match'
         68        SEND_VAL                                                 '%23%5Cd%23'
         69        SEND_VAR                                                 !4
         70        DO_ICALL                                         $42     
         71      > JMPZ                                                     $42, ->74
   31    72    >   ASSIGN_DIM                                               !2
         73        OP_DATA                                                  !4
   29    74    > > JMP                                                      ->66
         75    >   FE_FREE                                                  $41
   33    76        INIT_FCALL                                               'microtime'
         77        SEND_VAL                                                 1
         78        DO_ICALL                                         $44     
         79        SUB                                              ~45     !1, $44
         80        CONCAT                                           ~46     'foreach+%5Cd+took+', ~45
         81        CONCAT                                           ~47     ~46, '+seconds%0A'
         82        ECHO                                                     ~47
   36    83        INIT_FCALL                                               'microtime'
         84        SEND_VAL                                                 1
         85        DO_ICALL                                         $48     
         86        ASSIGN                                                   !1, $48
   37    87        ASSIGN                                                   !2, <array>
   39    88        INIT_FCALL                                               'preg_grep'
         89        SEND_VAL                                                 '%23%5Cd%23'
         90        SEND_VAR                                                 !0
         91        DO_ICALL                                         $51     
         92        ASSIGN                                                   !2, $51
   41    93        INIT_FCALL                                               'microtime'
         94        SEND_VAL                                                 1
         95        DO_ICALL                                         $53     
         96        SUB                                              ~54     !1, $53
         97        CONCAT                                           ~55     'preg_grep+%5Cd+took+', ~54
         98        CONCAT                                           ~56     ~55, '+seconds%0A'
         99        ECHO                                                     ~56
        100      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.48 ms | 1409 KiB | 21 Q