3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Service { public $class; public function __construct($class) { $this->class = $class; } } class Container { public $services = array(); } $container = new Container(); $start = memory_get_usage(); for ($i = 0; $i < 1000; $i++) { $container->services[] = new Service('Foo'.$i); } $delta = memory_get_usage() - $start; echo 'Memory usage of 1000 service objects: '.$delta, PHP_EOL; $container = new Container(); $start = memory_get_usage(); for ($i = 0; $i < 1000; $i++) { $container->services[] = array('Foo'.$i); } $delta = memory_get_usage() - $start; echo 'Memory usage of 1000 service arrays: '.$delta;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 8
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 33
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 33
Branch analysis from position: 41
Branch analysis from position: 33
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 8
Branch analysis from position: 18
Branch analysis from position: 8
filename:       /in/cAfcq
function name:  (null)
number of ops:  48
compiled vars:  !0 = $container, !1 = $start, !2 = $i, !3 = $delta
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $4      'Container'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   20     3        INIT_FCALL                                               'memory_get_usage'
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
   22     6        ASSIGN                                                   !2, 0
          7      > JMP                                                      ->16
   23     8    >   NEW                                              $12     'Service'
          9        CONCAT                                           ~13     'Foo', !2
         10        SEND_VAL_EX                                              ~13
         11        DO_FCALL                                      0          
         12        FETCH_OBJ_W                                      $10     !0, 'services'
         13        ASSIGN_DIM                                               $10
         14        OP_DATA                                                  $12
   22    15        PRE_INC                                                  !2
         16    >   IS_SMALLER                                               !2, 1000
         17      > JMPNZ                                                    ~16, ->8
   26    18    >   INIT_FCALL                                               'memory_get_usage'
         19        DO_ICALL                                         $17     
         20        SUB                                              ~18     $17, !1
         21        ASSIGN                                                   !3, ~18
   28    22        CONCAT                                           ~20     'Memory+usage+of+1000+service+objects%3A+', !3
         23        ECHO                                                     ~20
         24        ECHO                                                     '%0A'
   30    25        NEW                                              $21     'Container'
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !0, $21
   32    28        INIT_FCALL                                               'memory_get_usage'
         29        DO_ICALL                                         $24     
         30        ASSIGN                                                   !1, $24
   34    31        ASSIGN                                                   !2, 0
         32      > JMP                                                      ->39
   35    33    >   CONCAT                                           ~29     'Foo', !2
         34        INIT_ARRAY                                       ~30     ~29
         35        FETCH_OBJ_W                                      $27     !0, 'services'
         36        ASSIGN_DIM                                               $27
         37        OP_DATA                                                  ~30
   34    38        PRE_INC                                                  !2
         39    >   IS_SMALLER                                               !2, 1000
         40      > JMPNZ                                                    ~32, ->33
   38    41    >   INIT_FCALL                                               'memory_get_usage'
         42        DO_ICALL                                         $33     
         43        SUB                                              ~34     $33, !1
         44        ASSIGN                                                   !3, ~34
   40    45        CONCAT                                           ~36     'Memory+usage+of+1000+service+arrays%3A+', !3
         46        ECHO                                                     ~36
         47      > RETURN                                                   1

Class Service:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cAfcq
function name:  __construct
number of ops:  4
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        ASSIGN_OBJ                                               'class'
          2        OP_DATA                                                  !0
   10     3      > RETURN                                                   null

End of function __construct

End of class Service.

Class Container: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
131.53 ms | 1450 KiB | 14 Q