3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array_fill(0, 100000, true); function is_indexed_foreach($array) { $n = 0; foreach ($array as $key => $_) { if ($key !== $n++) { return false; } } return true; } function is_indexed_range($array) { return array_keys($array) === range(0, count($array) - 1); } printf("%.2f mb\n", memory_get_peak_usage() / 1024 / 1024); is_indexed_foreach($array); printf("%.2f mb\n", memory_get_peak_usage() / 1024 / 1024); is_indexed_range($array); printf("%.2f mb\n", memory_get_peak_usage() / 1024 / 1024);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FiWdk
function name:  (null)
number of ops:  37
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'array_fill'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 100000
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $1      
          5        ASSIGN                                                   !0, $1
   21     6        INIT_FCALL                                               'printf'
          7        SEND_VAL                                                 '%25.2f+mb%0A'
          8        INIT_FCALL                                               'memory_get_peak_usage'
          9        DO_ICALL                                         $3      
         10        DIV                                              ~4      $3, 1024
         11        DIV                                              ~5      ~4, 1024
         12        SEND_VAL                                                 ~5
         13        DO_ICALL                                                 
   23    14        INIT_FCALL                                               'is_indexed_foreach'
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0          
   25    17        INIT_FCALL                                               'printf'
         18        SEND_VAL                                                 '%25.2f+mb%0A'
         19        INIT_FCALL                                               'memory_get_peak_usage'
         20        DO_ICALL                                         $8      
         21        DIV                                              ~9      $8, 1024
         22        DIV                                              ~10     ~9, 1024
         23        SEND_VAL                                                 ~10
         24        DO_ICALL                                                 
   27    25        INIT_FCALL                                               'is_indexed_range'
         26        SEND_VAR                                                 !0
         27        DO_FCALL                                      0          
   29    28        INIT_FCALL                                               'printf'
         29        SEND_VAL                                                 '%25.2f+mb%0A'
         30        INIT_FCALL                                               'memory_get_peak_usage'
         31        DO_ICALL                                         $13     
         32        DIV                                              ~14     $13, 1024
         33        DIV                                              ~15     ~14, 1024
         34        SEND_VAL                                                 ~15
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Function is_indexed_foreach:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/FiWdk
function name:  is_indexed_foreach
number of ops:  14
compiled vars:  !0 = $array, !1 = $n, !2 = $_, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        ASSIGN                                                   !1, 0
    8     2      > FE_RESET_R                                       $5      !0, ->11
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->11
          4    >   ASSIGN                                                   !3, ~6
    9     5        POST_INC                                         ~8      !1
          6        IS_NOT_IDENTICAL                                         !3, ~8
          7      > JMPZ                                                     ~9, ->10
   10     8    >   FE_FREE                                                  $5
          9      > RETURN                                                   <false>
    8    10    > > JMP                                                      ->3
         11    >   FE_FREE                                                  $5
   14    12      > RETURN                                                   <true>
   15    13*     > RETURN                                                   null

End of function is_indexed_foreach

Function is_indexed_range:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FiWdk
function name:  is_indexed_range
number of ops:  13
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        INIT_FCALL                                               'array_keys'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        INIT_FCALL                                               'range'
          5        SEND_VAL                                                 0
          6        COUNT                                            ~2      !0
          7        SUB                                              ~3      ~2, 1
          8        SEND_VAL                                                 ~3
          9        DO_ICALL                                         $4      
         10        IS_IDENTICAL                                     ~5      $1, $4
         11      > RETURN                                                   ~5
   19    12*     > RETURN                                                   null

End of function is_indexed_range

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
196.29 ms | 1403 KiB | 25 Q