3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ "arr1" => [1, 2, 3, 4], "arr2" => ["a", "b", "c", "d"] ]; $start = microtime(1); foreach ($array as $arr) { foreach ($arr as $a) { echo $a; } } $first = microtime(1) - $start; $start = microtime(1); $all = array_merge($array["arr1"], $array["arr2"]); foreach ($all as $a) { echo $a; } $second = microtime(1) - $start; $start = microtime(1); function test_print($item, $key) { echo $item; } array_walk_recursive($array, 'test_print'); $third = microtime(1) - $start; $start = microtime(1); function loop($array){ foreach($array as $value){ if(is_array($value)){ loop($value); }else{ echo $value; } } } loop($array); $fourth = microtime(1) - $start; echo "\n\n"; echo "Nested: " . $first*1000 . "\n" . "array_merge: " . $second*1000 . "\n" . "array_walk_recursive: " . $third*1000 . "\n" . "Recursive function: " . $fourth*1000;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 11
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 13
filename:       /in/aFP6o
function name:  (null)
number of ops:  82
compiled vars:  !0 = $array, !1 = $start, !2 = $arr, !3 = $a, !4 = $first, !5 = $all, !6 = $second, !7 = $third, !8 = $fourth
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    7     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 1
          3        DO_ICALL                                         $10     
          4        ASSIGN                                                   !1, $10
    8     5      > FE_RESET_R                                       $12     !0, ->13
          6    > > FE_FETCH_R                                               $12, !2, ->13
    9     7    > > FE_RESET_R                                       $13     !2, ->11
          8    > > FE_FETCH_R                                               $13, !3, ->11
   10     9    >   ECHO                                                     !3
    9    10      > JMP                                                      ->8
         11    >   FE_FREE                                                  $13
    8    12      > JMP                                                      ->6
         13    >   FE_FREE                                                  $12
   13    14        INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 1
         16        DO_ICALL                                         $14     
         17        SUB                                              ~15     $14, !1
         18        ASSIGN                                                   !4, ~15
   16    19        INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 1
         21        DO_ICALL                                         $17     
         22        ASSIGN                                                   !1, $17
   17    23        INIT_FCALL                                               'array_merge'
         24        FETCH_DIM_R                                      ~19     !0, 'arr1'
         25        SEND_VAL                                                 ~19
         26        FETCH_DIM_R                                      ~20     !0, 'arr2'
         27        SEND_VAL                                                 ~20
         28        DO_ICALL                                         $21     
         29        ASSIGN                                                   !5, $21
   18    30      > FE_RESET_R                                       $23     !5, ->34
         31    > > FE_FETCH_R                                               $23, !3, ->34
   19    32    >   ECHO                                                     !3
   18    33      > JMP                                                      ->31
         34    >   FE_FREE                                                  $23
   22    35        INIT_FCALL                                               'microtime'
         36        SEND_VAL                                                 1
         37        DO_ICALL                                         $24     
         38        SUB                                              ~25     $24, !1
         39        ASSIGN                                                   !6, ~25
   25    40        INIT_FCALL                                               'microtime'
         41        SEND_VAL                                                 1
         42        DO_ICALL                                         $27     
         43        ASSIGN                                                   !1, $27
   31    44        INIT_FCALL                                               'array_walk_recursive'
         45        SEND_REF                                                 !0
         46        SEND_VAL                                                 'test_print'
         47        DO_ICALL                                                 
   32    48        INIT_FCALL                                               'microtime'
         49        SEND_VAL                                                 1
         50        DO_ICALL                                         $30     
         51        SUB                                              ~31     $30, !1
         52        ASSIGN                                                   !7, ~31
   34    53        INIT_FCALL                                               'microtime'
         54        SEND_VAL                                                 1
         55        DO_ICALL                                         $33     
         56        ASSIGN                                                   !1, $33
   44    57        INIT_FCALL                                               'loop'
         58        SEND_VAR                                                 !0
         59        DO_FCALL                                      0          
   45    60        INIT_FCALL                                               'microtime'
         61        SEND_VAL                                                 1
         62        DO_ICALL                                         $36     
         63        SUB                                              ~37     $36, !1
         64        ASSIGN                                                   !8, ~37
   48    65        ECHO                                                     '%0A%0A'
   49    66        MUL                                              ~39     !4, 1000
         67        CONCAT                                           ~40     'Nested%3A+', ~39
         68        CONCAT                                           ~41     ~40, '%0A'
         69        CONCAT                                           ~42     ~41, 'array_merge%3A+'
         70        MUL                                              ~43     !6, 1000
         71        CONCAT                                           ~44     ~42, ~43
         72        CONCAT                                           ~45     ~44, '%0A'
         73        CONCAT                                           ~46     ~45, 'array_walk_recursive%3A+'
         74        MUL                                              ~47     !7, 1000
         75        CONCAT                                           ~48     ~46, ~47
         76        CONCAT                                           ~49     ~48, '%0A'
         77        CONCAT                                           ~50     ~49, 'Recursive+function%3A+'
         78        MUL                                              ~51     !8, 1000
         79        CONCAT                                           ~52     ~50, ~51
         80        ECHO                                                     ~52
   50    81      > RETURN                                                   1

Function test_print:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aFP6o
function name:  test_print
number of ops:  4
compiled vars:  !0 = $item, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        ECHO                                                     !0
   29     3      > RETURN                                                   null

End of function test_print

Function loop:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 11
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/aFP6o
function name:  loop
number of ops:  13
compiled vars:  !0 = $array, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1      > FE_RESET_R                                       $2      !0, ->11
          2    > > FE_FETCH_R                                               $2, !1, ->11
   37     3    >   TYPE_CHECK                                  128          !1
          4      > JMPZ                                                     ~3, ->9
   38     5    >   INIT_FCALL_BY_NAME                                       'loop'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
   37     8      > JMP                                                      ->10
   40     9    >   ECHO                                                     !1
   36    10    > > JMP                                                      ->2
         11    >   FE_FREE                                                  $2
   43    12      > RETURN                                                   null

End of function loop

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.74 ms | 1024 KiB | 17 Q