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); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 134
Branch analysis from position: 134
2 jumps found. (Code = 44) Position 1 = 136, Position 2 = 2
Branch analysis from position: 136
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
2 jumps found. (Code = 44) Position 1 = 136, Position 2 = 2
Branch analysis from position: 136
Branch analysis from position: 2
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/577TT
function name:  (null)
number of ops:  137
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                                                      ->134
   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
   10   133        ASSIGN_OP                                     3          !0, 2
        134    >   IS_SMALLER                                               !0, 100000
        135      > JMPNZ                                                    ~75, ->2
   37   136    > > RETURN                                                   1

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