3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * My results: * * Average time to process 10,000 items, 100 runs * * Array:: 0.0034920692443848 * Obj: 0.026956255435944 */ /** * Class foo */ class Foo { /** * @var */ protected $bar; /** * Builds it. * * @param mixed $bar * Something bar */ public function __construct($bar) { $this->bar = $bar; } /** * Something. * * @return mixed * Something */ public function getBar() { return $this->bar; } } $foo['bar'] = 'baz'; $baz = new Foo('baz'); $cycles = 10000; $array = $obj = array(); for ($j = 0; $j < 100; $j++) { $start = microtime(TRUE); for ($i = 0; $i < $cycles; $i++) { $b = $foo['bar']; } $array[] = microtime(TRUE) - $start; $start = microtime(TRUE); for ($i = 0; $i < $cycles; $i++) { $b = $baz->getBar(); } $obj[] = microtime(TRUE) - $start; } echo "Array: "; echo array_sum($array) / count($array); echo "\n\nObject: "; echo array_sum($obj) / count($obj);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 11
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 17
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 34
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 11
Branch analysis from position: 49
Branch analysis from position: 11
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 34
Branch analysis from position: 40
Branch analysis from position: 34
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 17
Branch analysis from position: 22
Branch analysis from position: 17
filename:       /in/ASJLq
function name:  (null)
number of ops:  64
compiled vars:  !0 = $foo, !1 = $baz, !2 = $cycles, !3 = $array, !4 = $obj, !5 = $j, !6 = $start, !7 = $i, !8 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   ASSIGN_DIM                                               !0, 'bar'
          1        OP_DATA                                                  'baz'
   43     2        NEW                                              $10     'Foo'
          3        SEND_VAL_EX                                              'baz'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $10
   44     6        ASSIGN                                                   !2, 10000
   45     7        ASSIGN                                           ~14     !4, <array>
          8        ASSIGN                                                   !3, ~14
   46     9        ASSIGN                                                   !5, 0
         10      > JMP                                                      ->47
   47    11    >   INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $17     
         14        ASSIGN                                                   !6, $17
   48    15        ASSIGN                                                   !7, 0
         16      > JMP                                                      ->20
   49    17    >   FETCH_DIM_R                                      ~20     !0, 'bar'
         18        ASSIGN                                                   !8, ~20
   48    19        PRE_INC                                                  !7
         20    >   IS_SMALLER                                               !7, !2
         21      > JMPNZ                                                    ~23, ->17
   51    22    >   INIT_FCALL                                               'microtime'
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $25     
         25        SUB                                              ~26     $25, !6
         26        ASSIGN_DIM                                               !3
         27        OP_DATA                                                  ~26
   52    28        INIT_FCALL                                               'microtime'
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $27     
         31        ASSIGN                                                   !6, $27
   53    32        ASSIGN                                                   !7, 0
         33      > JMP                                                      ->38
   54    34    >   INIT_METHOD_CALL                                         !1, 'getBar'
         35        DO_FCALL                                      0  $30     
         36        ASSIGN                                                   !8, $30
   53    37        PRE_INC                                                  !7
         38    >   IS_SMALLER                                               !7, !2
         39      > JMPNZ                                                    ~33, ->34
   56    40    >   INIT_FCALL                                               'microtime'
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $35     
         43        SUB                                              ~36     $35, !6
         44        ASSIGN_DIM                                               !4
         45        OP_DATA                                                  ~36
   46    46        PRE_INC                                                  !5
         47    >   IS_SMALLER                                               !5, 100
         48      > JMPNZ                                                    ~38, ->11
   60    49    >   ECHO                                                     'Array%3A+'
   61    50        INIT_FCALL                                               'array_sum'
         51        SEND_VAR                                                 !3
         52        DO_ICALL                                         $39     
         53        COUNT                                            ~40     !3
         54        DIV                                              ~41     $39, ~40
         55        ECHO                                                     ~41
   62    56        ECHO                                                     '%0A%0AObject%3A+'
   63    57        INIT_FCALL                                               'array_sum'
         58        SEND_VAR                                                 !4
         59        DO_ICALL                                         $42     
         60        COUNT                                            ~43     !4
         61        DIV                                              ~44     $42, ~43
         62        ECHO                                                     ~44
         63      > RETURN                                                   1

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

End of function __construct

Function getbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ASJLq
function name:  getBar
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   FETCH_OBJ_R                                      ~0      'bar'
          1      > RETURN                                                   ~0
   40     2*     > RETURN                                                   null

End of function getbar

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.44 ms | 1400 KiB | 17 Q