3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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>'. PHP_EOL; } $array = range(0, 30000); test('foreach', function ($msg) use ($array) { echo $msg . ' before loop mem: '. mem() .PHP_EOL; foreach ($array as $v) { $b = $v; } echo $msg . ' after loop mem: '. mem() .PHP_EOL; }); test('foreach ref', function ($msg) use ($array) { echo $msg . ' before loop mem: '. mem() .PHP_EOL; foreach ($array as &$v) { $b = $v; } unset($v); echo $msg . ' after loop mem: '. mem() .PHP_EOL; }); test('for', function ($msg) use ($array) { echo $msg . ' before loop mem: '. mem() .PHP_EOL; $so = count($array); for ($i = 0; $i < $so; ++$i) { $b = $array[$i]; } echo $msg . ' after loop mem: '. mem() .PHP_EOL; }); test('while each -> list', function ($msg) use ($array) { echo $msg . ' before loop mem: '. mem() .PHP_EOL; while (list($k, $v) = each($array)) { $b =$v; } echo $msg . ' after loop mem: '. mem() .PHP_EOL; }); 'Memory peak: ' . round(memory_get_peak_usage() / 1048576, 3) .PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b9uMc
function name:  (null)
number of ops:  40
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 30000
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   21     5        INIT_FCALL                                               'test'
          6        SEND_VAL                                                 'foreach'
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fb9uMc%3A21%240'
          8        BIND_LEXICAL                                             ~3, !0
   27     9        SEND_VAL                                                 ~3
         10        DO_FCALL                                      0          
   28    11        INIT_FCALL                                               'test'
         12        SEND_VAL                                                 'foreach+ref'
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fb9uMc%3A28%241'
         14        BIND_LEXICAL                                             ~5, !0
   35    15        SEND_VAL                                                 ~5
         16        DO_FCALL                                      0          
   36    17        INIT_FCALL                                               'test'
         18        SEND_VAL                                                 'for'
         19        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fb9uMc%3A36%242'
         20        BIND_LEXICAL                                             ~7, !0
   43    21        SEND_VAL                                                 ~7
         22        DO_FCALL                                      0          
   44    23        INIT_FCALL                                               'test'
         24        SEND_VAL                                                 'while+each+-%3E+list'
         25        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fb9uMc%3A44%243'
         26        BIND_LEXICAL                                             ~9, !0
   50    27        SEND_VAL                                                 ~9
         28        DO_FCALL                                      0          
   52    29        INIT_FCALL                                               'round'
         30        INIT_FCALL                                               'memory_get_peak_usage'
         31        DO_ICALL                                         $11     
         32        DIV                                              ~12     $11, 1048576
         33        SEND_VAL                                                 ~12
         34        SEND_VAL                                                 3
         35        DO_ICALL                                         $13     
         36        CONCAT                                           ~14     'Memory+peak%3A+', $13
         37        CONCAT                                           ~15     ~14, '%0A'
         38        FREE                                                     ~15
         39      > RETURN                                                   1

Function bytestosize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b9uMc
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
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
    4     2        ASSIGN                                                   !2, <array>
    5     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
    6    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
    7    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/b9uMc
function name:  mem
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     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
   11     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/b9uMc
function name:  test
number of ops:  23
compiled vars:  !0 = $msg, !1 = $test, !2 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !2, $3
   15     6        INIT_DYNAMIC_CALL                                        !1
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   16     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'
         20        CONCAT                                           ~12     ~11, '%0A'
         21        ECHO                                                     ~12
   17    22      > RETURN                                                   null

End of function test

Function %00%7Bclosure%7D%2Fin%2Fb9uMc%3A21%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/b9uMc
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
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   22     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, '%0A'
          7        ECHO                                                     ~7
   23     8      > FE_RESET_R                                       $8      !1, ->12
          9    > > FE_FETCH_R                                               $8, !2, ->12
   24    10    >   ASSIGN                                                   !3, !2
   23    11      > JMP                                                      ->9
         12    >   FE_FREE                                                  $8
   26    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, '%0A'
         18        ECHO                                                     ~13
   27    19      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fb9uMc%3A21%240

Function %00%7Bclosure%7D%2Fin%2Fb9uMc%3A28%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/b9uMc
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
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   29     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, '%0A'
          7        ECHO                                                     ~7
   30     8      > FE_RESET_RW                                      $8      !1, ->12
          9    > > FE_FETCH_RW                                              $8, !2, ->12
   31    10    >   ASSIGN                                                   !3, !2
   30    11      > JMP                                                      ->9
         12    >   FE_FREE                                                  $8
   33    13        UNSET_CV                                                 !2
   34    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, '%0A'
         19        ECHO                                                     ~13
   35    20      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fb9uMc%3A28%241

Function %00%7Bclosure%7D%2Fin%2Fb9uMc%3A36%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/b9uMc
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
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   37     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, '%0A'
          7        ECHO                                                     ~8
   38     8        COUNT                                            ~9      !1
          9        ASSIGN                                                   !2, ~9
   39    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->15
   40    12    >   FETCH_DIM_R                                      ~12     !1, !3
         13        ASSIGN                                                   !4, ~12
   39    14        PRE_INC                                                  !3
         15    >   IS_SMALLER                                               !3, !2
         16      > JMPNZ                                                    ~15, ->12
   42    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, '%0A'
         22        ECHO                                                     ~19
   43    23      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fb9uMc%3A36%242

Function %00%7Bclosure%7D%2Fin%2Fb9uMc%3A44%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/b9uMc
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
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   45     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, '%0A'
          7        ECHO                                                     ~8
   46     8      > JMP                                                      ->10
   47     9    >   ASSIGN                                                   !2, !3
   46    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
   49    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, '%0A'
         23        ECHO                                                     ~18
   50    24      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fb9uMc%3A44%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.52 ms | 1410 KiB | 44 Q