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"; // precache it preg_match("#\d#", 0); $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 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 45
Branch analysis from position: 57
2 jumps found. (Code = 77) Position 1 = 70, Position 2 = 79
Branch analysis from position: 70
2 jumps found. (Code = 78) Position 1 = 71, Position 2 = 79
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 78
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 78
Branch analysis from position: 79
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 79
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 54
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 45
Branch analysis from position: 57
Branch analysis from position: 45
Branch analysis from position: 54
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/uO4GN
function name:  (null)
number of ops:  105
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                                               'preg_match'
         35        SEND_VAL                                                 '%23%5Cd%23'
         36        SEND_VAL                                                 0
         37        DO_ICALL                                                 
   18    38        INIT_FCALL                                               'microtime'
         39        SEND_VAL                                                 1
         40        DO_ICALL                                         $25     
         41        ASSIGN                                                   !1, $25
   19    42        ASSIGN                                                   !2, <array>
   21    43        ASSIGN                                                   !3, 0
         44      > JMP                                                      ->55
   22    45    >   INIT_FCALL                                               'preg_match'
         46        SEND_VAL                                                 '%23%5Cd%23'
         47        FETCH_DIM_R                                      ~29     !0, !3
         48        SEND_VAL                                                 ~29
         49        DO_ICALL                                         $30     
         50      > JMPZ                                                     $30, ->54
   23    51    >   FETCH_DIM_R                                      ~32     !0, !3
         52        ASSIGN_DIM                                               !2
         53        OP_DATA                                                  ~32
   21    54    >   PRE_INC                                                  !3
         55    >   IS_SMALLER                                               !3, 100
         56      > JMPNZ                                                    ~34, ->45
   25    57    >   INIT_FCALL                                               'microtime'
         58        SEND_VAL                                                 1
         59        DO_ICALL                                         $35     
         60        SUB                                              ~36     !1, $35
         61        CONCAT                                           ~37     'for+%5Cd+took+', ~36
         62        CONCAT                                           ~38     ~37, '+seconds%0A'
         63        ECHO                                                     ~38
   28    64        INIT_FCALL                                               'microtime'
         65        SEND_VAL                                                 1
         66        DO_ICALL                                         $39     
         67        ASSIGN                                                   !1, $39
   29    68        ASSIGN                                                   !2, <array>
   31    69      > FE_RESET_R                                       $42     !0, ->79
         70    > > FE_FETCH_R                                               $42, !4, ->79
   32    71    >   INIT_FCALL                                               'preg_match'
         72        SEND_VAL                                                 '%23%5Cd%23'
         73        SEND_VAR                                                 !4
         74        DO_ICALL                                         $43     
         75      > JMPZ                                                     $43, ->78
   33    76    >   ASSIGN_DIM                                               !2
         77        OP_DATA                                                  !4
   31    78    > > JMP                                                      ->70
         79    >   FE_FREE                                                  $42
   35    80        INIT_FCALL                                               'microtime'
         81        SEND_VAL                                                 1
         82        DO_ICALL                                         $45     
         83        SUB                                              ~46     !1, $45
         84        CONCAT                                           ~47     'foreach+%5Cd+took+', ~46
         85        CONCAT                                           ~48     ~47, '+seconds%0A'
         86        ECHO                                                     ~48
   38    87        INIT_FCALL                                               'microtime'
         88        SEND_VAL                                                 1
         89        DO_ICALL                                         $49     
         90        ASSIGN                                                   !1, $49
   39    91        ASSIGN                                                   !2, <array>
   41    92        INIT_FCALL                                               'preg_grep'
         93        SEND_VAL                                                 '%23%5Cd%23'
         94        SEND_VAR                                                 !0
         95        DO_ICALL                                         $52     
         96        ASSIGN                                                   !2, $52
   43    97        INIT_FCALL                                               'microtime'
         98        SEND_VAL                                                 1
         99        DO_ICALL                                         $54     
        100        SUB                                              ~55     !1, $54
        101        CONCAT                                           ~56     'preg_grep+%5Cd+took+', ~55
        102        CONCAT                                           ~57     ~56, '+seconds%0A'
        103        ECHO                                                     ~57
        104      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.21 ms | 1404 KiB | 21 Q