3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('NUM_INSTANCES', 10); define('NUM_TESTS', 10000); class TestObject { public $a; public $b; public $c; public function __construct($a,$b,$c) { $this->a = $a; $this->b = $b; $this->c = $c; } } class Test { public function getObjects() { $a = array(); for ($i=0; $i<NUM_INSTANCES; $i++) $a[] = new TestObject('a','b','c'); return $a; } public function getArrays() { $a = array(); for ($i=0; $i<NUM_INSTANCES; $i++) $a[] = $this->buildArray('a', 'b', 'c'); return $a; } public function buildArray($a, $b, $c) { $array = array(); $array['a'] = $a; $array['b'] = $b; $array['c'] = $c; return $array; } public function useObject($o) { $a = $o->a; $b = $o->b; $o->c = 'xxx'; } public function useArray($o) { $a = $o['a']; $b = $o['b']; $o['c'] = 'xxx'; } } $test = new Test; // Benchmark with objects: $start = microtime(true); for ($i=0; $i<NUM_TESTS; $i++) { $x = $test->getObjects(); foreach ($x as $y) $test->useObject($y); } echo "\nObject time = " . (microtime(true)-$start) . "\n\n"; // Benchmark with arrays: $start = microtime(true); for ($i=0; $i<NUM_TESTS; $i++) { $x = $test->getArrays(); foreach ($x as $y) $test->useArray($y); } echo "\nArray time = " . (microtime(true)-$start) . "\n\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 17
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 44
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 53
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 44
Branch analysis from position: 58
Branch analysis from position: 44
Branch analysis from position: 53
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 17
Branch analysis from position: 31
Branch analysis from position: 17
Branch analysis from position: 26
filename:       /in/ZogHd
function name:  (null)
number of ops:  66
compiled vars:  !0 = $test, !1 = $start, !2 = $i, !3 = $x, !4 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'NUM_INSTANCES'
          2        SEND_VAL                                                 10
          3        DO_ICALL                                                 
    4     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'NUM_TESTS'
          6        SEND_VAL                                                 10000
          7        DO_ICALL                                                 
   62     8        NEW                                              $7      'Test'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !0, $7
   65    11        INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $10     
         14        ASSIGN                                                   !1, $10
   66    15        ASSIGN                                                   !2, 0
         16      > JMP                                                      ->28
   68    17    >   INIT_METHOD_CALL                                         !0, 'getObjects'
         18        DO_FCALL                                      0  $13     
         19        ASSIGN                                                   !3, $13
   69    20      > FE_RESET_R                                       $15     !3, ->26
         21    > > FE_FETCH_R                                               $15, !4, ->26
   70    22    >   INIT_METHOD_CALL                                         !0, 'useObject'
         23        SEND_VAR_EX                                              !4
         24        DO_FCALL                                      0          
   69    25      > JMP                                                      ->21
         26    >   FE_FREE                                                  $15
   66    27        PRE_INC                                                  !2
         28    >   FETCH_CONSTANT                                   ~18     'NUM_TESTS'
         29        IS_SMALLER                                               !2, ~18
         30      > JMPNZ                                                    ~19, ->17
   72    31    >   INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $20     
         34        SUB                                              ~21     $20, !1
         35        CONCAT                                           ~22     '%0AObject+time+%3D+', ~21
         36        CONCAT                                           ~23     ~22, '%0A%0A'
         37        ECHO                                                     ~23
   75    38        INIT_FCALL                                               'microtime'
         39        SEND_VAL                                                 <true>
         40        DO_ICALL                                         $24     
         41        ASSIGN                                                   !1, $24
   76    42        ASSIGN                                                   !2, 0
         43      > JMP                                                      ->55
   78    44    >   INIT_METHOD_CALL                                         !0, 'getArrays'
         45        DO_FCALL                                      0  $27     
         46        ASSIGN                                                   !3, $27
   79    47      > FE_RESET_R                                       $29     !3, ->53
         48    > > FE_FETCH_R                                               $29, !4, ->53
   80    49    >   INIT_METHOD_CALL                                         !0, 'useArray'
         50        SEND_VAR_EX                                              !4
         51        DO_FCALL                                      0          
   79    52      > JMP                                                      ->48
         53    >   FE_FREE                                                  $29
   76    54        PRE_INC                                                  !2
         55    >   FETCH_CONSTANT                                   ~32     'NUM_TESTS'
         56        IS_SMALLER                                               !2, ~32
         57      > JMPNZ                                                    ~33, ->44
   82    58    >   INIT_FCALL                                               'microtime'
         59        SEND_VAL                                                 <true>
         60        DO_ICALL                                         $34     
         61        SUB                                              ~35     $34, !1
         62        CONCAT                                           ~36     '%0AArray+time+%3D+', ~35
         63        CONCAT                                           ~37     ~36, '%0A%0A'
         64        ECHO                                                     ~37
         65      > RETURN                                                   1

Class TestObject:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZogHd
function name:  __construct
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   14     3        ASSIGN_OBJ                                               'a'
          4        OP_DATA                                                  !0
   15     5        ASSIGN_OBJ                                               'b'
          6        OP_DATA                                                  !1
   16     7        ASSIGN_OBJ                                               'c'
          8        OP_DATA                                                  !2
   17     9      > RETURN                                                   null

End of function __construct

End of class TestObject.

Class Test:
Function getobjects:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 3
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 3
Branch analysis from position: 14
Branch analysis from position: 3
filename:       /in/ZogHd
function name:  getObjects
number of ops:  16
compiled vars:  !0 = $a, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, <array>
   25     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->11
   26     3    >   NEW                                              $5      'TestObject'
          4        SEND_VAL_EX                                              'a'
          5        SEND_VAL_EX                                              'b'
          6        SEND_VAL_EX                                              'c'
          7        DO_FCALL                                      0          
          8        ASSIGN_DIM                                               !0
          9        OP_DATA                                                  $5
   25    10        PRE_INC                                                  !1
         11    >   FETCH_CONSTANT                                   ~8      'NUM_INSTANCES'
         12        IS_SMALLER                                               !1, ~8
         13      > JMPNZ                                                    ~9, ->3
   27    14    > > RETURN                                                   !0
   28    15*     > RETURN                                                   null

End of function getobjects

Function getarrays:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 3
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 3
Branch analysis from position: 14
Branch analysis from position: 3
filename:       /in/ZogHd
function name:  getArrays
number of ops:  16
compiled vars:  !0 = $a, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ASSIGN                                                   !0, <array>
   33     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->11
   34     3    >   INIT_METHOD_CALL                                         'buildArray'
          4        SEND_VAL_EX                                              'a'
          5        SEND_VAL_EX                                              'b'
          6        SEND_VAL_EX                                              'c'
          7        DO_FCALL                                      0  $5      
          8        ASSIGN_DIM                                               !0
          9        OP_DATA                                                  $5
   33    10        PRE_INC                                                  !1
         11    >   FETCH_CONSTANT                                   ~7      'NUM_INSTANCES'
         12        IS_SMALLER                                               !1, ~7
         13      > JMPNZ                                                    ~8, ->3
   35    14    > > RETURN                                                   !0
   36    15*     > RETURN                                                   null

End of function getarrays

Function buildarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZogHd
function name:  buildArray
number of ops:  12
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   40     3        ASSIGN                                                   !3, <array>
   41     4        ASSIGN_DIM                                               !3, 'a'
          5        OP_DATA                                                  !0
   42     6        ASSIGN_DIM                                               !3, 'b'
          7        OP_DATA                                                  !1
   43     8        ASSIGN_DIM                                               !3, 'c'
          9        OP_DATA                                                  !2
   44    10      > RETURN                                                   !3
   45    11*     > RETURN                                                   null

End of function buildarray

Function useobject:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZogHd
function name:  useObject
number of ops:  8
compiled vars:  !0 = $o, !1 = $a, !2 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   49     1        FETCH_OBJ_R                                      ~3      !0, 'a'
          2        ASSIGN                                                   !1, ~3
   50     3        FETCH_OBJ_R                                      ~5      !0, 'b'
          4        ASSIGN                                                   !2, ~5
   51     5        ASSIGN_OBJ                                               !0, 'c'
          6        OP_DATA                                                  'xxx'
   52     7      > RETURN                                                   null

End of function useobject

Function usearray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZogHd
function name:  useArray
number of ops:  8
compiled vars:  !0 = $o, !1 = $a, !2 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   56     1        FETCH_DIM_R                                      ~3      !0, 'a'
          2        ASSIGN                                                   !1, ~3
   57     3        FETCH_DIM_R                                      ~5      !0, 'b'
          4        ASSIGN                                                   !2, ~5
   58     5        ASSIGN_DIM                                               !0, 'c'
          6        OP_DATA                                                  'xxx'
   59     7      > RETURN                                                   null

End of function usearray

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.7 ms | 1408 KiB | 17 Q