3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('memory_limit', '2G'); set_time_limit(600); function bytesToSize($bytes, $precision = 2) { $symbols = array('B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb'); $exp = (int)floor(log($bytes) / log(1024)); return sprintf('%.'. $precision .'f '. $symbols[$exp], $bytes / pow(1024, floor($exp))); } function mem() { return bytesToSize(memory_get_usage(true)); } function test($msg, $test) { $t = microtime(true); $test($msg); echo $msg .': <b>'. sprintf('%.6f', microtime(true) - $t) .'</b><br>'; } $array = range(0, 3000000); test('foreach', function ($msg) use ($array) { echo $msg . ' before loop mem: '. mem() .'<br>'; foreach ($array as $v) { $b = $v; } echo $msg . ' after loop mem: '. mem() .'<br>'; }); test('foreach ref', function ($msg) use ($array) { echo $msg . ' before loop mem: '. mem() .'<br>'; foreach ($array as &$v) { $b = $v; } unset($v); echo $msg . ' after loop mem: '. mem() .'<br>'; }); test('for', function ($msg) use ($array) { echo $msg . ' before loop mem: '. mem() .'<br>'; $so = count($array); for ($i = 0; $i < $so; ++$i) { $b = $array[$i]; } echo $msg . ' after loop mem: '. mem() .'<br>'; }); test('while each -> list', function ($msg) use ($array) { echo $msg . ' before loop mem: '. mem() .'<br>'; while (list($k, $v) = each($array)) { $b =$v; } echo $msg . ' after loop mem: '. mem() .'<br>'; });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NT00B
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                                               'ini_set'
          1        SEND_VAL                                                 'memory_limit'
          2        SEND_VAL                                                 '2G'
          3        DO_ICALL                                                 
    4     4        INIT_FCALL                                               'set_time_limit'
          5        SEND_VAL                                                 600
          6        DO_ICALL                                                 
   22     7        INIT_FCALL                                               'range'
          8        SEND_VAL                                                 0
          9        SEND_VAL                                                 3000000
         10        DO_ICALL                                         $3      
         11        ASSIGN                                                   !0, $3
   24    12        INIT_FCALL                                               'test'
         13        SEND_VAL                                                 'foreach'
         14        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FNT00B%3A24%240'
         15        BIND_LEXICAL                                             ~5, !0
   30    16        SEND_VAL                                                 ~5
         17        DO_FCALL                                      0          
   31    18        INIT_FCALL                                               'test'
         19        SEND_VAL                                                 'foreach+ref'
         20        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FNT00B%3A31%241'
         21        BIND_LEXICAL                                             ~7, !0
   38    22        SEND_VAL                                                 ~7
         23        DO_FCALL                                      0          
   39    24        INIT_FCALL                                               'test'
         25        SEND_VAL                                                 'for'
         26        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FNT00B%3A39%242'
         27        BIND_LEXICAL                                             ~9, !0
   46    28        SEND_VAL                                                 ~9
         29        DO_FCALL                                      0          
   47    30        INIT_FCALL                                               'test'
         31        SEND_VAL                                                 'while+each+-%3E+list'
         32        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FNT00B%3A47%243'
         33        BIND_LEXICAL                                             ~11, !0
   53    34        SEND_VAL                                                 ~11
         35        DO_FCALL                                      0          
         36      > RETURN                                                   1

Function bytestosize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NT00B
function name:  bytesToSize
number of ops:  33
compiled vars:  !0 = $bytes, !1 = $precision, !2 = $symbols, !3 = $exp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
    7     2        ASSIGN                                                   !2, <array>
    8     3        INIT_FCALL                                               'floor'
          4        INIT_FCALL                                               'log'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $5      
          7        INIT_FCALL                                               'log'
          8        SEND_VAL                                                 1024
          9        DO_ICALL                                         $6      
         10        DIV                                              ~7      $5, $6
         11        SEND_VAL                                                 ~7
         12        DO_ICALL                                         $8      
         13        CAST                                          4  ~9      $8
         14        ASSIGN                                                   !3, ~9
    9    15        INIT_FCALL                                               'sprintf'
         16        CONCAT                                           ~11     '%25.', !1
         17        CONCAT                                           ~12     ~11, 'f+'
         18        FETCH_DIM_R                                      ~13     !2, !3
         19        CONCAT                                           ~14     ~12, ~13
         20        SEND_VAL                                                 ~14
         21        INIT_FCALL                                               'pow'
         22        SEND_VAL                                                 1024
         23        INIT_FCALL                                               'floor'
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $15     
         26        SEND_VAR                                                 $15
         27        DO_ICALL                                         $16     
         28        DIV                                              ~17     !0, $16
         29        SEND_VAL                                                 ~17
         30        DO_ICALL                                         $18     
         31      > RETURN                                                   $18
   10    32*     > RETURN                                                   null

End of function bytestosize

Function mem:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NT00B
function name:  mem
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'bytestosize'
          1        INIT_FCALL                                               'memory_get_usage'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $0      
          4        SEND_VAR                                                 $0
          5        DO_FCALL                                      0  $1      
          6      > RETURN                                                   $1
   14     7*     > RETURN                                                   null

End of function mem

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NT00B
function name:  test
number of ops:  22
compiled vars:  !0 = $msg, !1 = $test, !2 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !2, $3
   18     6        INIT_DYNAMIC_CALL                                        !1
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   19     9        CONCAT                                           ~6      !0, '%3A+%3Cb%3E'
         10        INIT_FCALL                                               'sprintf'
         11        SEND_VAL                                                 '%25.6f'
         12        INIT_FCALL                                               'microtime'
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $7      
         15        SUB                                              ~8      $7, !2
         16        SEND_VAL                                                 ~8
         17        DO_ICALL                                         $9      
         18        CONCAT                                           ~10     ~6, $9
         19        CONCAT                                           ~11     ~10, '%3C%2Fb%3E%3Cbr%3E'
         20        ECHO                                                     ~11
   20    21      > RETURN                                                   null

End of function test

Function %00%7Bclosure%7D%2Fin%2FNT00B%3A24%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/NT00B
function name:  {closure}
number of ops:  20
compiled vars:  !0 = $msg, !1 = $array, !2 = $v, !3 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   25     2        CONCAT                                           ~4      !0, '+before+loop+mem%3A+'
          3        INIT_FCALL                                               'mem'
          4        DO_FCALL                                      0  $5      
          5        CONCAT                                           ~6      ~4, $5
          6        CONCAT                                           ~7      ~6, '%3Cbr%3E'
          7        ECHO                                                     ~7
   26     8      > FE_RESET_R                                       $8      !1, ->12
          9    > > FE_FETCH_R                                               $8, !2, ->12
   27    10    >   ASSIGN                                                   !3, !2
   26    11      > JMP                                                      ->9
         12    >   FE_FREE                                                  $8
   29    13        CONCAT                                           ~10     !0, '+after+loop+mem%3A+'
         14        INIT_FCALL                                               'mem'
         15        DO_FCALL                                      0  $11     
         16        CONCAT                                           ~12     ~10, $11
         17        CONCAT                                           ~13     ~12, '%3Cbr%3E'
         18        ECHO                                                     ~13
   30    19      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FNT00B%3A24%240

Function %00%7Bclosure%7D%2Fin%2FNT00B%3A31%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
2 jumps found. (Code = 126) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/NT00B
function name:  {closure}
number of ops:  21
compiled vars:  !0 = $msg, !1 = $array, !2 = $v, !3 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   32     2        CONCAT                                           ~4      !0, '+before+loop+mem%3A+'
          3        INIT_FCALL                                               'mem'
          4        DO_FCALL                                      0  $5      
          5        CONCAT                                           ~6      ~4, $5
          6        CONCAT                                           ~7      ~6, '%3Cbr%3E'
          7        ECHO                                                     ~7
   33     8      > FE_RESET_RW                                      $8      !1, ->12
          9    > > FE_FETCH_RW                                              $8, !2, ->12
   34    10    >   ASSIGN                                                   !3, !2
   33    11      > JMP                                                      ->9
         12    >   FE_FREE                                                  $8
   36    13        UNSET_CV                                                 !2
   37    14        CONCAT                                           ~10     !0, '+after+loop+mem%3A+'
         15        INIT_FCALL                                               'mem'
         16        DO_FCALL                                      0  $11     
         17        CONCAT                                           ~12     ~10, $11
         18        CONCAT                                           ~13     ~12, '%3Cbr%3E'
         19        ECHO                                                     ~13
   38    20      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FNT00B%3A31%241

Function %00%7Bclosure%7D%2Fin%2FNT00B%3A39%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 12
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 12
Branch analysis from position: 17
Branch analysis from position: 12
filename:       /in/NT00B
function name:  {closure}
number of ops:  24
compiled vars:  !0 = $msg, !1 = $array, !2 = $so, !3 = $i, !4 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   40     2        CONCAT                                           ~5      !0, '+before+loop+mem%3A+'
          3        INIT_FCALL                                               'mem'
          4        DO_FCALL                                      0  $6      
          5        CONCAT                                           ~7      ~5, $6
          6        CONCAT                                           ~8      ~7, '%3Cbr%3E'
          7        ECHO                                                     ~8
   41     8        COUNT                                            ~9      !1
          9        ASSIGN                                                   !2, ~9
   42    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->15
   43    12    >   FETCH_DIM_R                                      ~12     !1, !3
         13        ASSIGN                                                   !4, ~12
   42    14        PRE_INC                                                  !3
         15    >   IS_SMALLER                                               !3, !2
         16      > JMPNZ                                                    ~15, ->12
   45    17    >   CONCAT                                           ~16     !0, '+after+loop+mem%3A+'
         18        INIT_FCALL                                               'mem'
         19        DO_FCALL                                      0  $17     
         20        CONCAT                                           ~18     ~16, $17
         21        CONCAT                                           ~19     ~18, '%3Cbr%3E'
         22        ECHO                                                     ~19
   46    23      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FNT00B%3A39%242

Function %00%7Bclosure%7D%2Fin%2FNT00B%3A47%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 9
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 9
Branch analysis from position: 18
Branch analysis from position: 9
filename:       /in/NT00B
function name:  {closure}
number of ops:  25
compiled vars:  !0 = $msg, !1 = $array, !2 = $b, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   48     2        CONCAT                                           ~5      !0, '+before+loop+mem%3A+'
          3        INIT_FCALL                                               'mem'
          4        DO_FCALL                                      0  $6      
          5        CONCAT                                           ~7      ~5, $6
          6        CONCAT                                           ~8      ~7, '%3Cbr%3E'
          7        ECHO                                                     ~8
   49     8      > JMP                                                      ->10
   50     9    >   ASSIGN                                                   !2, !3
   49    10    >   INIT_FCALL_BY_NAME                                       'each'
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0  $10     
         13        FETCH_LIST_R                                     $11     $10, 0
         14        ASSIGN                                                   !4, $11
         15        FETCH_LIST_R                                     $13     $10, 1
         16        ASSIGN                                                   !3, $13
         17      > JMPNZ                                                    $10, ->9
   52    18    >   CONCAT                                           ~15     !0, '+after+loop+mem%3A+'
         19        INIT_FCALL                                               'mem'
         20        DO_FCALL                                      0  $16     
         21        CONCAT                                           ~17     ~15, $16
         22        CONCAT                                           ~18     ~17, '%3Cbr%3E'
         23        ECHO                                                     ~18
   53    24      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FNT00B%3A47%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.84 ms | 1419 KiB | 44 Q