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

Function formatmemoryusage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BtQ4I
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:
158.11 ms | 1423 KiB | 31 Q