3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array(); for($i = 0; $i < pow(10, 5); $i++) { $a[$i] = array( md5(microtime(true)) ); } $sum = 0; $times['for']['before'] = microtime(true); for($j = 0; $i < count($a); $i++) { $sum += 1000; } $times['for']['after'] = microtime(true); unset($sum); $sum = 0; $times['foreach']['before'] = microtime(true); foreach($a as $k) { $sum += 1000; } $times['foreach']['after'] = microtime(true); unset($sum); $t_for = $times['for']['after'] - $times['for']['before']; $t_foreach = $times['foreach']['after'] - $times['foreach']['before']; var_dump(array($times, 'is for faster than foreach?' => $t_for < $t_foreach, $t_for, $t_foreach));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 3
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 28
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 51
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 28
Branch analysis from position: 33
Branch analysis from position: 28
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 3
Branch analysis from position: 19
Branch analysis from position: 3
filename:       /in/cNOlk
function name:  (null)
number of ops:  80
compiled vars:  !0 = $a, !1 = $i, !2 = $sum, !3 = $times, !4 = $j, !5 = $k, !6 = $t_for, !7 = $t_foreach
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->13
    6     3    >   INIT_FCALL                                               'md5'
          4        INIT_FCALL                                               'microtime'
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $11     
          7        SEND_VAR                                                 $11
          8        DO_ICALL                                         $12     
          9        INIT_ARRAY                                       ~13     $12
    5    10        ASSIGN_DIM                                               !0, !1
    6    11        OP_DATA                                                  ~13
    4    12        PRE_INC                                                  !1
         13    >   INIT_FCALL                                               'pow'
         14        SEND_VAL                                                 10
         15        SEND_VAL                                                 5
         16        DO_ICALL                                         $15     
         17        IS_SMALLER                                               !1, $15
         18      > JMPNZ                                                    ~16, ->3
   10    19    >   ASSIGN                                                   !2, 0
   11    20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $20     
         23        FETCH_DIM_W                                      $18     !3, 'for'
         24        ASSIGN_DIM                                               $18, 'before'
         25        OP_DATA                                                  $20
   12    26        ASSIGN                                                   !4, 0
         27      > JMP                                                      ->30
   13    28    >   ASSIGN_OP                                     1          !2, 1000
   12    29        PRE_INC                                                  !1
         30    >   COUNT                                            ~24     !0
         31        IS_SMALLER                                               !1, ~24
         32      > JMPNZ                                                    ~25, ->28
   15    33    >   INIT_FCALL                                               'microtime'
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $28     
         36        FETCH_DIM_W                                      $26     !3, 'for'
         37        ASSIGN_DIM                                               $26, 'after'
         38        OP_DATA                                                  $28
   16    39        UNSET_CV                                                 !2
   18    40        ASSIGN                                                   !2, 0
   19    41        INIT_FCALL                                               'microtime'
         42        SEND_VAL                                                 <true>
         43        DO_ICALL                                         $32     
         44        FETCH_DIM_W                                      $30     !3, 'foreach'
         45        ASSIGN_DIM                                               $30, 'before'
         46        OP_DATA                                                  $32
   20    47      > FE_RESET_R                                       $33     !0, ->51
         48    > > FE_FETCH_R                                               $33, !5, ->51
   21    49    >   ASSIGN_OP                                     1          !2, 1000
   20    50      > JMP                                                      ->48
         51    >   FE_FREE                                                  $33
   23    52        INIT_FCALL                                               'microtime'
         53        SEND_VAL                                                 <true>
         54        DO_ICALL                                         $37     
         55        FETCH_DIM_W                                      $35     !3, 'foreach'
         56        ASSIGN_DIM                                               $35, 'after'
         57        OP_DATA                                                  $37
   24    58        UNSET_CV                                                 !2
   26    59        FETCH_DIM_R                                      ~38     !3, 'for'
         60        FETCH_DIM_R                                      ~39     ~38, 'after'
         61        FETCH_DIM_R                                      ~40     !3, 'for'
         62        FETCH_DIM_R                                      ~41     ~40, 'before'
         63        SUB                                              ~42     ~39, ~41
         64        ASSIGN                                                   !6, ~42
   27    65        FETCH_DIM_R                                      ~44     !3, 'foreach'
         66        FETCH_DIM_R                                      ~45     ~44, 'after'
         67        FETCH_DIM_R                                      ~46     !3, 'foreach'
         68        FETCH_DIM_R                                      ~47     ~46, 'before'
         69        SUB                                              ~48     ~45, ~47
         70        ASSIGN                                                   !7, ~48
   29    71        INIT_FCALL                                               'var_dump'
         72        INIT_ARRAY                                       ~50     !3
         73        IS_SMALLER                                       ~51     !6, !7
         74        ADD_ARRAY_ELEMENT                                ~50     ~51, 'is+for+faster+than+foreach%3F'
         75        ADD_ARRAY_ELEMENT                                ~50     !6
         76        ADD_ARRAY_ELEMENT                                ~50     !7
         77        SEND_VAL                                                 ~50
         78        DO_ICALL                                                 
         79      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.23 ms | 1400 KiB | 21 Q