3v4l.org

run code in 300+ PHP versions simultaneously
<?php function formatMemoryUsage($usage) { $unit = array(' B', 'kB', 'MB', 'GB', 'TB'); $factor = floor((strlen($usage) - 1) / 3); return sprintf('%.2f %s (%d bytes) ', $usage / pow(1024, $factor), $unit[$factor], $usage); } for($size = 1000; $size < 100000; $size *= 2) { echo PHP_EOL . '> Testing size: ' . number_format($size) . PHP_EOL; echo ' Array()' . PHP_EOL; for($s = microtime(true), $m = memory_get_usage(), $container = Array(), $i = 0; $i < $size; $i++) $container[$i] = null; echo ' - Write - time : ' . str_pad(microtime(true) - $s, 20, '0') . ' - memory: ' . formatMemoryUsage(memory_get_usage(true) - $m) . PHP_EOL; $s = microtime(true); foreach ($container as $key => $value) { $void = $value; } echo ' - Read - time : ' . str_pad(microtime(true) - $s, 20, '0') . PHP_EOL; unset($container); echo ' SplFixedArray()' . PHP_EOL; for($s = microtime(true), $m = memory_get_usage(), $container = new SplFixedArray($size), $i = 0; $i < $size; $i++) $container[$i] = null; echo ' - Write - time : ' . str_pad(microtime(true) - $s, 20, '0') . ' - memory: ' . formatMemoryUsage(memory_get_usage(true) - $m) . PHP_EOL; $s = microtime(true); foreach ($container as $key => $value) { $void = $value; } echo ' - Read - time : ' . str_pad(microtime(true) - $s, 20, '0') . PHP_EOL; unset($container); echo ' SplFixedArray()' . PHP_EOL; for($s = microtime(true), $m = memory_get_usage(), $container = new SplFixedArray($size), $i = 0; $i < $size; $i++) $container[$i] = null; echo ' - Write - time : ' . str_pad(microtime(true) - $s, 20, '0') . ' - memory: ' . formatMemoryUsage(memory_get_usage(true) - $m) . PHP_EOL; $s = microtime(true); foreach ($container as $key => $value) { $void = $value; } echo ' - Read - time : ' . str_pad(microtime(true) - $s, 20, '0') . PHP_EOL; unset($container); echo ' SplFixedArray()' . PHP_EOL; for($s = microtime(true), $m = memory_get_usage(), $container = new SplFixedArray($size), $i = 0; $i < $size; $i++) $container[$i] = null; echo ' - Write - time : ' . str_pad(microtime(true) - $s, 20, '0') . ' - memory: ' . formatMemoryUsage(memory_get_usage(true) - $m) . PHP_EOL; $s = microtime(true); foreach ($container as $key => $value) { $void = $value; } echo ' - Read - time : ' . str_pad(microtime(true) - $s, 20, '0') . PHP_EOL; unset($container); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 258
Branch analysis from position: 258
2 jumps found. (Code = 44) Position 1 = 260, Position 2 = 2
Branch analysis from position: 260
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 19
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 50, Position 2 = 54
Branch analysis from position: 50
2 jumps found. (Code = 78) Position 1 = 51, Position 2 = 54
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 87, Position 2 = 82
Branch analysis from position: 87
2 jumps found. (Code = 77) Position 1 = 113, Position 2 = 117
Branch analysis from position: 113
2 jumps found. (Code = 78) Position 1 = 114, Position 2 = 117
Branch analysis from position: 114
1 jumps found. (Code = 42) Position 1 = 113
Branch analysis from position: 113
Branch analysis from position: 117
1 jumps found. (Code = 42) Position 1 = 148
Branch analysis from position: 148
2 jumps found. (Code = 44) Position 1 = 150, Position 2 = 145
Branch analysis from position: 150
2 jumps found. (Code = 77) Position 1 = 176, Position 2 = 180
Branch analysis from position: 176
2 jumps found. (Code = 78) Position 1 = 177, Position 2 = 180
Branch analysis from position: 177
1 jumps found. (Code = 42) Position 1 = 176
Branch analysis from position: 176
Branch analysis from position: 180
1 jumps found. (Code = 42) Position 1 = 211
Branch analysis from position: 211
2 jumps found. (Code = 44) Position 1 = 213, Position 2 = 208
Branch analysis from position: 213
2 jumps found. (Code = 77) Position 1 = 239, Position 2 = 243
Branch analysis from position: 239
2 jumps found. (Code = 78) Position 1 = 240, Position 2 = 243
Branch analysis from position: 240
1 jumps found. (Code = 42) Position 1 = 239
Branch analysis from position: 239
Branch analysis from position: 243
2 jumps found. (Code = 44) Position 1 = 260, Position 2 = 2
Branch analysis from position: 260
Branch analysis from position: 2
Branch analysis from position: 243
Branch analysis from position: 208
2 jumps found. (Code = 44) Position 1 = 213, Position 2 = 208
Branch analysis from position: 213
Branch analysis from position: 208
Branch analysis from position: 180
Branch analysis from position: 145
2 jumps found. (Code = 44) Position 1 = 150, Position 2 = 145
Branch analysis from position: 150
Branch analysis from position: 145
Branch analysis from position: 117
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 87, Position 2 = 82
Branch analysis from position: 87
Branch analysis from position: 82
Branch analysis from position: 54
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 19
Branch analysis from position: 24
Branch analysis from position: 19
filename:       /in/AtP9i
function name:  (null)
number of ops:  261
compiled vars:  !0 = $size, !1 = $s, !2 = $m, !3 = $container, !4 = $i, !5 = $value, !6 = $key, !7 = $void
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   ASSIGN                                                   !0, 1000
          1      > JMP                                                      ->258
   11     2    >   INIT_FCALL                                               'number_format'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $9      
          5        CONCAT                                           ~10     '%0A%3E+Testing+size%3A+', $9
          6        CONCAT                                           ~11     ~10, '%0A'
          7        ECHO                                                     ~11
   12     8        ECHO                                                     '+++Array%28%29%0A'
   14     9        INIT_FCALL                                               'microtime'
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $12     
         12        ASSIGN                                                   !1, $12
         13        INIT_FCALL                                               'memory_get_usage'
         14        DO_ICALL                                         $14     
         15        ASSIGN                                                   !2, $14
         16        ASSIGN                                                   !3, <array>
         17        ASSIGN                                                   !4, 0
         18      > JMP                                                      ->22
         19    >   ASSIGN_DIM                                               !3, !4
         20        OP_DATA                                                  null
         21        PRE_INC                                                  !4
         22    >   IS_SMALLER                                               !4, !0
         23      > JMPNZ                                                    ~20, ->19
   15    24    >   INIT_FCALL                                               'str_pad'
         25        INIT_FCALL                                               'microtime'
         26        SEND_VAL                                                 <true>
         27        DO_ICALL                                         $21     
         28        SUB                                              ~22     $21, !1
         29        SEND_VAL                                                 ~22
         30        SEND_VAL                                                 20
         31        SEND_VAL                                                 '0'
         32        DO_ICALL                                         $23     
         33        CONCAT                                           ~24     '++++++-+Write+++++++++-+time+++%3A+', $23
         34        CONCAT                                           ~25     ~24, '+++++-+memory%3A+'
         35        INIT_FCALL                                               'formatmemoryusage'
         36        INIT_FCALL                                               'memory_get_usage'
         37        SEND_VAL                                                 <true>
         38        DO_ICALL                                         $26     
         39        SUB                                              ~27     $26, !2
         40        SEND_VAL                                                 ~27
         41        DO_FCALL                                      0  $28     
         42        CONCAT                                           ~29     ~25, $28
         43        CONCAT                                           ~30     ~29, '%0A'
         44        ECHO                                                     ~30
   17    45        INIT_FCALL                                               'microtime'
         46        SEND_VAL                                                 <true>
         47        DO_ICALL                                         $31     
         48        ASSIGN                                                   !1, $31
   18    49      > FE_RESET_R                                       $33     !3, ->54
         50    > > FE_FETCH_R                                       ~34     $33, !5, ->54
         51    >   ASSIGN                                                   !6, ~34
   19    52        ASSIGN                                                   !7, !5
   18    53      > JMP                                                      ->50
         54    >   FE_FREE                                                  $33
   21    55        INIT_FCALL                                               'str_pad'
         56        INIT_FCALL                                               'microtime'
         57        SEND_VAL                                                 <true>
         58        DO_ICALL                                         $37     
         59        SUB                                              ~38     $37, !1
         60        SEND_VAL                                                 ~38
         61        SEND_VAL                                                 20
         62        SEND_VAL                                                 '0'
         63        DO_ICALL                                         $39     
         64        CONCAT                                           ~40     '++++++-+Read++++++++++-+time+++%3A+', $39
         65        CONCAT                                           ~41     ~40, '%0A'
         66        ECHO                                                     ~41
   23    67        UNSET_CV                                                 !3
   25    68        ECHO                                                     '+++SplFixedArray%28%29%0A'
   27    69        INIT_FCALL                                               'microtime'
         70        SEND_VAL                                                 <true>
         71        DO_ICALL                                         $42     
         72        ASSIGN                                                   !1, $42
         73        INIT_FCALL                                               'memory_get_usage'
         74        DO_ICALL                                         $44     
         75        ASSIGN                                                   !2, $44
         76        NEW                                              $46     'SplFixedArray'
         77        SEND_VAR_EX                                              !0
         78        DO_FCALL                                      0          
         79        ASSIGN                                                   !3, $46
         80        ASSIGN                                                   !4, 0
         81      > JMP                                                      ->85
         82    >   ASSIGN_DIM                                               !3, !4
         83        OP_DATA                                                  null
         84        PRE_INC                                                  !4
         85    >   IS_SMALLER                                               !4, !0
         86      > JMPNZ                                                    ~52, ->82
   28    87    >   INIT_FCALL                                               'str_pad'
         88        INIT_FCALL                                               'microtime'
         89        SEND_VAL                                                 <true>
         90        DO_ICALL                                         $53     
         91        SUB                                              ~54     $53, !1
         92        SEND_VAL                                                 ~54
         93        SEND_VAL                                                 20
         94        SEND_VAL                                                 '0'
         95        DO_ICALL                                         $55     
         96        CONCAT                                           ~56     '++++++-+Write+++++++++-+time+++%3A+', $55
         97        CONCAT                                           ~57     ~56, '+++++-+memory%3A+'
         98        INIT_FCALL                                               'formatmemoryusage'
         99        INIT_FCALL                                               'memory_get_usage'
        100        SEND_VAL                                                 <true>
        101        DO_ICALL                                         $58     
        102        SUB                                              ~59     $58, !2
        103        SEND_VAL                                                 ~59
        104        DO_FCALL                                      0  $60     
        105        CONCAT                                           ~61     ~57, $60
        106        CONCAT                                           ~62     ~61, '%0A'
        107        ECHO                                                     ~62
   30   108        INIT_FCALL                                               'microtime'
        109        SEND_VAL                                                 <true>
        110        DO_ICALL                                         $63     
        111        ASSIGN                                                   !1, $63
   31   112      > FE_RESET_R                                       $65     !3, ->117
        113    > > FE_FETCH_R                                       ~66     $65, !5, ->117
        114    >   ASSIGN                                                   !6, ~66
   32   115        ASSIGN                                                   !7, !5
   31   116      > JMP                                                      ->113
        117    >   FE_FREE                                                  $65
   34   118        INIT_FCALL                                               'str_pad'
        119        INIT_FCALL                                               'microtime'
        120        SEND_VAL                                                 <true>
        121        DO_ICALL                                         $69     
        122        SUB                                              ~70     $69, !1
        123        SEND_VAL                                                 ~70
        124        SEND_VAL                                                 20
        125        SEND_VAL                                                 '0'
        126        DO_ICALL                                         $71     
        127        CONCAT                                           ~72     '++++++-+Read++++++++++-+time+++%3A+', $71
        128        CONCAT                                           ~73     ~72, '%0A'
        129        ECHO                                                     ~73
   36   130        UNSET_CV                                                 !3
   38   131        ECHO                                                     '+++SplFixedArray%28%29%0A'
   40   132        INIT_FCALL                                               'microtime'
        133        SEND_VAL                                                 <true>
        134        DO_ICALL                                         $74     
        135        ASSIGN                                                   !1, $74
        136        INIT_FCALL                                               'memory_get_usage'
        137        DO_ICALL                                         $76     
        138        ASSIGN                                                   !2, $76
        139        NEW                                              $78     'SplFixedArray'
        140        SEND_VAR_EX                                              !0
        141        DO_FCALL                                      0          
        142        ASSIGN                                                   !3, $78
        143        ASSIGN                                                   !4, 0
        144      > JMP                                                      ->148
        145    >   ASSIGN_DIM                                               !3, !4
        146        OP_DATA                                                  null
        147        PRE_INC                                                  !4
        148    >   IS_SMALLER                                               !4, !0
        149      > JMPNZ                                                    ~84, ->145
   41   150    >   INIT_FCALL                                               'str_pad'
        151        INIT_FCALL                                               'microtime'
        152        SEND_VAL                                                 <true>
        153        DO_ICALL                                         $85     
        154        SUB                                              ~86     $85, !1
        155        SEND_VAL                                                 ~86
        156        SEND_VAL                                                 20
        157        SEND_VAL                                                 '0'
        158        DO_ICALL                                         $87     
        159        CONCAT                                           ~88     '++++++-+Write+++++++++-+time+++%3A+', $87
        160        CONCAT                                           ~89     ~88, '+++++-+memory%3A+'
        161        INIT_FCALL                                               'formatmemoryusage'
        162        INIT_FCALL                                               'memory_get_usage'
        163        SEND_VAL                                                 <true>
        164        DO_ICALL                                         $90     
        165        SUB                                              ~91     $90, !2
        166        SEND_VAL                                                 ~91
        167        DO_FCALL                                      0  $92     
        168        CONCAT                                           ~93     ~89, $92
        169        CONCAT                                           ~94     ~93, '%0A'
        170        ECHO                                                     ~94
   43   171        INIT_FCALL                                               'microtime'
        172        SEND_VAL                                                 <true>
        173        DO_ICALL                                         $95     
        174        ASSIGN                                                   !1, $95
   44   175      > FE_RESET_R                                       $97     !3, ->180
        176    > > FE_FETCH_R                                       ~98     $97, !5, ->180
        177    >   ASSIGN                                                   !6, ~98
   45   178        ASSIGN                                                   !7, !5
   44   179      > JMP                                                      ->176
        180    >   FE_FREE                                                  $97
   47   181        INIT_FCALL                                               'str_pad'
        182        INIT_FCALL                                               'microtime'
        183        SEND_VAL                                                 <true>
        184        DO_ICALL                                         $101    
        185        SUB                                              ~102    $101, !1
        186        SEND_VAL                                                 ~102
        187        SEND_VAL                                                 20
        188        SEND_VAL                                                 '0'
        189        DO_ICALL                                         $103    
        190        CONCAT                                           ~104    '++++++-+Read++++++++++-+time+++%3A+', $103
        191        CONCAT                                           ~105    ~104, '%0A'
        192        ECHO                                                     ~105
   49   193        UNSET_CV                                                 !3
   51   194        ECHO                                                     '+++SplFixedArray%28%29%0A'
   53   195        INIT_FCALL                                               'microtime'
        196        SEND_VAL                                                 <true>
        197        DO_ICALL                                         $106    
        198        ASSIGN                                                   !1, $106
        199        INIT_FCALL                                               'memory_get_usage'
        200        DO_ICALL                                         $108    
        201        ASSIGN                                                   !2, $108
        202        NEW                                              $110    'SplFixedArray'
        203        SEND_VAR_EX                                              !0
        204        DO_FCALL                                      0          
        205        ASSIGN                                                   !3, $110
        206        ASSIGN                                                   !4, 0
        207      > JMP                                                      ->211
        208    >   ASSIGN_DIM                                               !3, !4
        209        OP_DATA                                                  null
        210        PRE_INC                                                  !4
        211    >   IS_SMALLER                                               !4, !0
        212      > JMPNZ                                                    ~116, ->208
   54   213    >   INIT_FCALL                                               'str_pad'
        214        INIT_FCALL                                               'microtime'
        215        SEND_VAL                                                 <true>
        216        DO_ICALL                                         $117    
        217        SUB                                              ~118    $117, !1
        218        SEND_VAL                                                 ~118
        219        SEND_VAL                                                 20
        220        SEND_VAL                                                 '0'
        221        DO_ICALL                                         $119    
        222        CONCAT                                           ~120    '++++++-+Write+++++++++-+time+++%3A+', $119
        223        CONCAT                                           ~121    ~120, '+++++-+memory%3A+'
        224        INIT_FCALL                                               'formatmemoryusage'
        225        INIT_FCALL                                               'memory_get_usage'
        226        SEND_VAL                                                 <true>
        227        DO_ICALL                                         $122    
        228        SUB                                              ~123    $122, !2
        229        SEND_VAL                                                 ~123
        230        DO_FCALL                                      0  $124    
        231        CONCAT                                           ~125    ~121, $124
        232        CONCAT                                           ~126    ~125, '%0A'
        233        ECHO                                                     ~126
   56   234        INIT_FCALL                                               'microtime'
        235        SEND_VAL                                                 <true>
        236        DO_ICALL                                         $127    
        237        ASSIGN                                                   !1, $127
   57   238      > FE_RESET_R                                       $129    !3, ->243
        239    > > FE_FETCH_R                                       ~130    $129, !5, ->243
        240    >   ASSIGN                                                   !6, ~130
   58   241        ASSIGN                                                   !7, !5
   57   242      > JMP                                                      ->239
        243    >   FE_FREE                                                  $129
   60   244        INIT_FCALL                                               'str_pad'
        245        INIT_FCALL                                               'microtime'
        246        SEND_VAL                                                 <true>
        247        DO_ICALL                                         $133    
        248        SUB                                              ~134    $133, !1
        249        SEND_VAL                                                 ~134
        250        SEND_VAL                                                 20
        251        SEND_VAL                                                 '0'
        252        DO_ICALL                                         $135    
        253        CONCAT                                           ~136    '++++++-+Read++++++++++-+time+++%3A+', $135
        254        CONCAT                                           ~137    ~136, '%0A'
        255        ECHO                                                     ~137
   62   256        UNSET_CV                                                 !3
   10   257        ASSIGN_OP                                     3          !0, 2
        258    >   IS_SMALLER                                               !0, 100000
        259      > JMPNZ                                                    ~139, ->2
   63   260    > > RETURN                                                   1

Function formatmemoryusage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AtP9i
function name:  formatMemoryUsage
number of ops:  23
compiled vars:  !0 = $usage, !1 = $unit, !2 = $factor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'floor'
          3        STRLEN                                           ~4      !0
          4        SUB                                              ~5      ~4, 1
          5        DIV                                              ~6      ~5, 3
          6        SEND_VAL                                                 ~6
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !2, $7
    7     9        INIT_FCALL                                               'sprintf'
         10        SEND_VAL                                                 '%25.2f+%25s+%28%25d+bytes%29+'
         11        INIT_FCALL                                               'pow'
         12        SEND_VAL                                                 1024
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $9      
         15        DIV                                              ~10     !0, $9
         16        SEND_VAL                                                 ~10
         17        FETCH_DIM_R                                      ~11     !1, !2
         18        SEND_VAL                                                 ~11
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $12     
         21      > RETURN                                                   $12
    8    22*     > RETURN                                                   null

End of function formatmemoryusage

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.11 ms | 1423 KiB | 31 Q