3v4l.org

run code in 300+ PHP versions simultaneously
<?php ## preperations; just a simple environment state $test_iterations = 100; $test_arr_size = 1000; // a shared function that makes use of the loop; this should // ensure no funny bussiness is happening to fool the test function test($input) { echo '<!-- '.trim($input).' -->'; } // for each test we create a array this should avoid any of the // arrays internal representation or optimizations from getting // in the way. // normal array $test_arr1 = array(); $test_arr2 = array(); $test_arr3 = array(); // hash tables $test_arr4 = array(); $test_arr5 = array(); for ($i = 0; $i < $test_arr_size; ++$i) { mt_srand(); $hash = md5(mt_rand()); $key = substr($hash, 0, 5).$i; $test_arr1[$i] = $test_arr2[$i] = $test_arr3[$i] = $test_arr4[$key] = $test_arr5[$key] = $hash; } ## foreach $start = microtime(true); for ($j = 0; $j < $test_iterations; ++$j) { foreach ($test_arr1 as $k => $v) { test($v); } } echo '<strong>foreach</strong> '.(microtime(true) - $start).'<br />'; ## foreach (using reference) $start = microtime(true); for ($j = 0; $j < $test_iterations; ++$j) { foreach ($test_arr2 as &$value) { test($value); } } echo '<strong>foreach</strong> (using reference) '.(microtime(true) - $start).'<br />'; ## for $start = microtime(true); for ($j = 0; $j < $test_iterations; ++$j) { $size = count($test_arr3); for ($i = 0; $i < $size; ++$i) { test($test_arr3[$i]); } } echo '<strong>for</strong> '.(microtime(true) - $start).'<br />'; ## foreach (hash table) $start = microtime(true); for ($j = 0; $j < $test_iterations; ++$j) { foreach ($test_arr4 as $k => $v) { test($v); } } echo '<strong>foreach</strong> (hash table) '.(microtime(true) - $start).'<br />'; ## for (hash table) $start = microtime(true); for ($j = 0; $j < $test_iterations; ++$j) { $keys = array_keys($test_arr5); $size = sizeOf($test_arr5); for ($i = 0; $i < $size; ++$i) { test($test_arr5[$keys[$i]]); } } echo '<strong>for</strong> (hash table) '.(microtime(true) - $start).'<br />';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 9
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 43
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 67
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 102
Branch analysis from position: 102
2 jumps found. (Code = 44) Position 1 = 104, Position 2 = 90
Branch analysis from position: 104
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
2 jumps found. (Code = 44) Position 1 = 128, Position 2 = 117
Branch analysis from position: 128
1 jumps found. (Code = 42) Position 1 = 158
Branch analysis from position: 158
2 jumps found. (Code = 44) Position 1 = 160, Position 2 = 141
Branch analysis from position: 160
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 141
1 jumps found. (Code = 42) Position 1 = 155
Branch analysis from position: 155
2 jumps found. (Code = 44) Position 1 = 157, Position 2 = 149
Branch analysis from position: 157
2 jumps found. (Code = 44) Position 1 = 160, Position 2 = 141
Branch analysis from position: 160
Branch analysis from position: 141
Branch analysis from position: 149
2 jumps found. (Code = 44) Position 1 = 157, Position 2 = 149
Branch analysis from position: 157
Branch analysis from position: 149
Branch analysis from position: 117
2 jumps found. (Code = 77) Position 1 = 118, Position 2 = 124
Branch analysis from position: 118
2 jumps found. (Code = 78) Position 1 = 119, Position 2 = 124
Branch analysis from position: 119
1 jumps found. (Code = 42) Position 1 = 118
Branch analysis from position: 118
Branch analysis from position: 124
2 jumps found. (Code = 44) Position 1 = 128, Position 2 = 117
Branch analysis from position: 128
Branch analysis from position: 117
Branch analysis from position: 124
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 99
Branch analysis from position: 99
2 jumps found. (Code = 44) Position 1 = 101, Position 2 = 94
Branch analysis from position: 101
2 jumps found. (Code = 44) Position 1 = 104, Position 2 = 90
Branch analysis from position: 104
Branch analysis from position: 90
Branch analysis from position: 94
2 jumps found. (Code = 44) Position 1 = 101, Position 2 = 94
Branch analysis from position: 101
Branch analysis from position: 94
Branch analysis from position: 67
2 jumps found. (Code = 125) Position 1 = 68, Position 2 = 73
Branch analysis from position: 68
2 jumps found. (Code = 126) Position 1 = 69, Position 2 = 73
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 67
Branch analysis from position: 77
Branch analysis from position: 67
Branch analysis from position: 73
Branch analysis from position: 43
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 50
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 50
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 43
Branch analysis from position: 54
Branch analysis from position: 43
Branch analysis from position: 50
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 9
Branch analysis from position: 37
Branch analysis from position: 9
filename:       /in/iF78D
function name:  (null)
number of ops:  168
compiled vars:  !0 = $test_iterations, !1 = $test_arr_size, !2 = $test_arr1, !3 = $test_arr2, !4 = $test_arr3, !5 = $test_arr4, !6 = $test_arr5, !7 = $i, !8 = $hash, !9 = $key, !10 = $start, !11 = $j, !12 = $v, !13 = $k, !14 = $value, !15 = $size, !16 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 100
    5     1        ASSIGN                                                   !1, 1000
   19     2        ASSIGN                                                   !2, <array>
   20     3        ASSIGN                                                   !3, <array>
   21     4        ASSIGN                                                   !4, <array>
   23     5        ASSIGN                                                   !5, <array>
   24     6        ASSIGN                                                   !6, <array>
   26     7        ASSIGN                                                   !7, 0
          8      > JMP                                                      ->35
   28     9    >   INIT_FCALL                                               'mt_srand'
         10        DO_ICALL                                                 
   29    11        INIT_FCALL                                               'md5'
         12        INIT_FCALL                                               'mt_rand'
         13        DO_ICALL                                         $26     
         14        SEND_VAR                                                 $26
         15        DO_ICALL                                         $27     
         16        ASSIGN                                                   !8, $27
   30    17        INIT_FCALL                                               'substr'
         18        SEND_VAR                                                 !8
         19        SEND_VAL                                                 0
         20        SEND_VAL                                                 5
         21        DO_ICALL                                         $29     
         22        CONCAT                                           ~30     $29, !7
         23        ASSIGN                                                   !9, ~30
   32    24        ASSIGN_DIM                                       ~36     !6, !9
   33    25        OP_DATA                                                  !8
   32    26        ASSIGN_DIM                                       ~35     !5, !9
   33    27        OP_DATA                                                  ~36
   32    28        ASSIGN_DIM                                       ~34     !4, !7
   33    29        OP_DATA                                                  ~35
   32    30        ASSIGN_DIM                                       ~33     !3, !7
   33    31        OP_DATA                                                  ~34
   32    32        ASSIGN_DIM                                               !2, !7
   33    33        OP_DATA                                                  ~33
   26    34        PRE_INC                                                  !7
         35    >   IS_SMALLER                                               !7, !1
         36      > JMPNZ                                                    ~38, ->9
   38    37    >   INIT_FCALL                                               'microtime'
         38        SEND_VAL                                                 <true>
         39        DO_ICALL                                         $39     
         40        ASSIGN                                                   !10, $39
   39    41        ASSIGN                                                   !11, 0
         42      > JMP                                                      ->52
   41    43    > > FE_RESET_R                                       $42     !2, ->50
         44    > > FE_FETCH_R                                       ~43     $42, !12, ->50
         45    >   ASSIGN                                                   !13, ~43
   43    46        INIT_FCALL                                               'test'
         47        SEND_VAR                                                 !12
         48        DO_FCALL                                      0          
   41    49      > JMP                                                      ->44
         50    >   FE_FREE                                                  $42
   39    51        PRE_INC                                                  !11
         52    >   IS_SMALLER                                               !11, !0
         53      > JMPNZ                                                    ~47, ->43
   46    54    >   INIT_FCALL                                               'microtime'
         55        SEND_VAL                                                 <true>
         56        DO_ICALL                                         $48     
         57        SUB                                              ~49     $48, !10
         58        CONCAT                                           ~50     '%3Cstrong%3Eforeach%3C%2Fstrong%3E+', ~49
         59        CONCAT                                           ~51     ~50, '%3Cbr+%2F%3E'
         60        ECHO                                                     ~51
   50    61        INIT_FCALL                                               'microtime'
         62        SEND_VAL                                                 <true>
         63        DO_ICALL                                         $52     
         64        ASSIGN                                                   !10, $52
   51    65        ASSIGN                                                   !11, 0
         66      > JMP                                                      ->75
   53    67    > > FE_RESET_RW                                      $55     !3, ->73
         68    > > FE_FETCH_RW                                              $55, !14, ->73
   55    69    >   INIT_FCALL                                               'test'
         70        SEND_VAR                                                 !14
         71        DO_FCALL                                      0          
   53    72      > JMP                                                      ->68
         73    >   FE_FREE                                                  $55
   51    74        PRE_INC                                                  !11
         75    >   IS_SMALLER                                               !11, !0
         76      > JMPNZ                                                    ~58, ->67
   58    77    >   INIT_FCALL                                               'microtime'
         78        SEND_VAL                                                 <true>
         79        DO_ICALL                                         $59     
         80        SUB                                              ~60     $59, !10
         81        CONCAT                                           ~61     '%3Cstrong%3Eforeach%3C%2Fstrong%3E+%28using+reference%29+', ~60
         82        CONCAT                                           ~62     ~61, '%3Cbr+%2F%3E'
         83        ECHO                                                     ~62
   62    84        INIT_FCALL                                               'microtime'
         85        SEND_VAL                                                 <true>
         86        DO_ICALL                                         $63     
         87        ASSIGN                                                   !10, $63
   63    88        ASSIGN                                                   !11, 0
         89      > JMP                                                      ->102
   65    90    >   COUNT                                            ~66     !4
         91        ASSIGN                                                   !15, ~66
   66    92        ASSIGN                                                   !7, 0
         93      > JMP                                                      ->99
   68    94    >   INIT_FCALL                                               'test'
         95        FETCH_DIM_R                                      ~69     !4, !7
         96        SEND_VAL                                                 ~69
         97        DO_FCALL                                      0          
   66    98        PRE_INC                                                  !7
         99    >   IS_SMALLER                                               !7, !15
        100      > JMPNZ                                                    ~72, ->94
   63   101    >   PRE_INC                                                  !11
        102    >   IS_SMALLER                                               !11, !0
        103      > JMPNZ                                                    ~74, ->90
   71   104    >   INIT_FCALL                                               'microtime'
        105        SEND_VAL                                                 <true>
        106        DO_ICALL                                         $75     
        107        SUB                                              ~76     $75, !10
        108        CONCAT                                           ~77     '%3Cstrong%3Efor%3C%2Fstrong%3E+', ~76
        109        CONCAT                                           ~78     ~77, '%3Cbr+%2F%3E'
        110        ECHO                                                     ~78
   75   111        INIT_FCALL                                               'microtime'
        112        SEND_VAL                                                 <true>
        113        DO_ICALL                                         $79     
        114        ASSIGN                                                   !10, $79
   76   115        ASSIGN                                                   !11, 0
        116      > JMP                                                      ->126
   78   117    > > FE_RESET_R                                       $82     !5, ->124
        118    > > FE_FETCH_R                                       ~83     $82, !12, ->124
        119    >   ASSIGN                                                   !13, ~83
   80   120        INIT_FCALL                                               'test'
        121        SEND_VAR                                                 !12
        122        DO_FCALL                                      0          
   78   123      > JMP                                                      ->118
        124    >   FE_FREE                                                  $82
   76   125        PRE_INC                                                  !11
        126    >   IS_SMALLER                                               !11, !0
        127      > JMPNZ                                                    ~87, ->117
   83   128    >   INIT_FCALL                                               'microtime'
        129        SEND_VAL                                                 <true>
        130        DO_ICALL                                         $88     
        131        SUB                                              ~89     $88, !10
        132        CONCAT                                           ~90     '%3Cstrong%3Eforeach%3C%2Fstrong%3E+%28hash+table%29+', ~89
        133        CONCAT                                           ~91     ~90, '%3Cbr+%2F%3E'
        134        ECHO                                                     ~91
   87   135        INIT_FCALL                                               'microtime'
        136        SEND_VAL                                                 <true>
        137        DO_ICALL                                         $92     
        138        ASSIGN                                                   !10, $92
   88   139        ASSIGN                                                   !11, 0
        140      > JMP                                                      ->158
   90   141    >   INIT_FCALL                                               'array_keys'
        142        SEND_VAR                                                 !6
        143        DO_ICALL                                         $95     
        144        ASSIGN                                                   !16, $95
   91   145        COUNT                                            ~97     !6
        146        ASSIGN                                                   !15, ~97
   92   147        ASSIGN                                                   !7, 0
        148      > JMP                                                      ->155
   94   149    >   INIT_FCALL                                               'test'
        150        FETCH_DIM_R                                      ~100    !16, !7
        151        FETCH_DIM_R                                      ~101    !6, ~100
        152        SEND_VAL                                                 ~101
        153        DO_FCALL                                      0          
   92   154        PRE_INC                                                  !7
        155    >   IS_SMALLER                                               !7, !15
        156      > JMPNZ                                                    ~104, ->149
   88   157    >   PRE_INC                                                  !11
        158    >   IS_SMALLER                                               !11, !0
        159      > JMPNZ                                                    ~106, ->141
   97   160    >   INIT_FCALL                                               'microtime'
        161        SEND_VAL                                                 <true>
        162        DO_ICALL                                         $107    
        163        SUB                                              ~108    $107, !10
        164        CONCAT                                           ~109    '%3Cstrong%3Efor%3C%2Fstrong%3E+%28hash+table%29+', ~108
        165        CONCAT                                           ~110    ~109, '%3Cbr+%2F%3E'
        166        ECHO                                                     ~110
        167      > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iF78D
function name:  test
number of ops:  8
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'trim'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        CONCAT                                           ~2      '%3C%21--+', $1
          5        CONCAT                                           ~3      ~2, '+--%3E'
          6        ECHO                                                     ~3
   12     7      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.29 ms | 1415 KiB | 32 Q