3v4l.org

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.25 ms | 1400 KiB | 21 Q