3v4l.org

run code in 300+ PHP versions simultaneously
<?php // setting either of these to false will prevent memory leak $assoc = true; $unserialize = true; function formatBytes($size, $precision = 2) { $base = log($size, 1024); $suffixes = [ '', 'K', 'M', 'G', 'T' ]; return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)]; } function load($str) { global $assoc, $unserialize; $php = serialize($assoc ? [ $str => 1 ] : [ $str ]); if ($unserialize) unserialize($php); } for ($ctr = 0; $ctr < 50000; $ctr++) load("foo_$ctr"); echo 'Usage: ', formatBytes(memory_get_usage()) , "\n"; echo 'Peak: ', formatBytes(memory_get_peak_usage()) , "\n";
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 = 12, Position 2 = 4
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
Branch analysis from position: 4
filename:       /in/KPJ62
function name:  (null)
number of ops:  29
compiled vars:  !0 = $assoc, !1 = $unserialize, !2 = $ctr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <true>
    5     1        ASSIGN                                                   !1, <true>
   22     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->10
   23     4    >   INIT_FCALL                                               'load'
          5        NOP                                                      
          6        FAST_CONCAT                                      ~6      'foo_', !2
          7        SEND_VAL                                                 ~6
          8        DO_FCALL                                      0          
   22     9        PRE_INC                                                  !2
         10    >   IS_SMALLER                                               !2, 50000
         11      > JMPNZ                                                    ~9, ->4
   25    12    >   ECHO                                                     'Usage%3A+'
         13        INIT_FCALL                                               'formatbytes'
         14        INIT_FCALL                                               'memory_get_usage'
         15        DO_ICALL                                         $10     
         16        SEND_VAR                                                 $10
         17        DO_FCALL                                      0  $11     
         18        ECHO                                                     $11
         19        ECHO                                                     '%0A'
   26    20        ECHO                                                     'Peak%3A++'
         21        INIT_FCALL                                               'formatbytes'
         22        INIT_FCALL                                               'memory_get_peak_usage'
         23        DO_ICALL                                         $12     
         24        SEND_VAR                                                 $12
         25        DO_FCALL                                      0  $13     
         26        ECHO                                                     $13
         27        ECHO                                                     '%0A'
         28      > RETURN                                                   1

Function formatbytes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KPJ62
function name:  formatBytes
number of ops:  28
compiled vars:  !0 = $size, !1 = $precision, !2 = $base, !3 = $suffixes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
    8     2        INIT_FCALL                                               'log'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 1024
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !2, $4
    9     7        ASSIGN                                                   !3, <array>
   11     8        INIT_FCALL                                               'round'
          9        INIT_FCALL                                               'pow'
         10        SEND_VAL                                                 1024
         11        INIT_FCALL                                               'floor'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $7      
         14        SUB                                              ~8      !2, $7
         15        SEND_VAL                                                 ~8
         16        DO_ICALL                                         $9      
         17        SEND_VAR                                                 $9
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $10     
         20        CONCAT                                           ~11     $10, '+'
         21        INIT_FCALL                                               'floor'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $12     
         24        FETCH_DIM_R                                      ~13     !3, $12
         25        CONCAT                                           ~14     ~11, ~13
         26      > RETURN                                                   ~14
   12    27*     > RETURN                                                   null

End of function formatbytes

Function load:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
Branch analysis from position: 17
filename:       /in/KPJ62
function name:  load
number of ops:  18
compiled vars:  !0 = $str, !1 = $assoc, !2 = $unserialize, !3 = $php
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        BIND_GLOBAL                                              !1, 'assoc'
          2        BIND_GLOBAL                                              !2, 'unserialize'
   17     3        INIT_FCALL                                               'serialize'
          4      > JMPZ                                                     !1, ->8
          5    >   INIT_ARRAY                                       ~4      1, !0
          6        QM_ASSIGN                                        ~5      ~4
          7      > JMP                                                      ->10
          8    >   INIT_ARRAY                                       ~6      !0
          9        QM_ASSIGN                                        ~5      ~6
         10    >   SEND_VAL                                                 ~5
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !3, $7
   18    13      > JMPZ                                                     !2, ->17
   19    14    >   INIT_FCALL                                               'unserialize'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                                 
   20    17    > > RETURN                                                   null

End of function load

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.41 ms | 952 KiB | 33 Q