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_sum($array) / count($array); 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/XZ5B2
function name:  (null)
number of ops:  62
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
-------------------------------------------------------------------------------------
   41     0  E >   ASSIGN_DIM                                               !0, 'bar'
          1        OP_DATA                                                  'baz'
   42     2        NEW                                              $10     'Foo'
          3        SEND_VAL_EX                                              'baz'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $10
   43     6        ASSIGN                                                   !2, 10000
   44     7        ASSIGN                                           ~14     !4, <array>
          8        ASSIGN                                                   !3, ~14
   45     9        ASSIGN                                                   !5, 0
         10      > JMP                                                      ->47
   46    11    >   INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $17     
         14        ASSIGN                                                   !6, $17
   47    15        ASSIGN                                                   !7, 0
         16      > JMP                                                      ->20
   48    17    >   FETCH_DIM_R                                      ~20     !0, 'bar'
         18        ASSIGN                                                   !8, ~20
   47    19        PRE_INC                                                  !7
         20    >   IS_SMALLER                                               !7, !2
         21      > JMPNZ                                                    ~23, ->17
   50    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
   51    28        INIT_FCALL                                               'microtime'
         29        SEND_VAL                                                 <true>
         30        DO_ICALL                                         $27     
         31        ASSIGN                                                   !6, $27
   52    32        ASSIGN                                                   !7, 0
         33      > JMP                                                      ->38
   53    34    >   INIT_METHOD_CALL                                         !1, 'getBar'
         35        DO_FCALL                                      0  $30     
         36        ASSIGN                                                   !8, $30
   52    37        PRE_INC                                                  !7
         38    >   IS_SMALLER                                               !7, !2
         39      > JMPNZ                                                    ~33, ->34
   55    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
   45    46        PRE_INC                                                  !5
         47    >   IS_SMALLER                                               !5, 100
         48      > JMPNZ                                                    ~38, ->11
   58    49    >   INIT_FCALL                                               'array_sum'
         50        SEND_VAR                                                 !3
         51        DO_ICALL                                         $39     
         52        COUNT                                            ~40     !3
         53        DIV                                              ~41     $39, ~40
         54        ECHO                                                     ~41
   59    55        INIT_FCALL                                               'array_sum'
         56        SEND_VAR                                                 !4
         57        DO_ICALL                                         $42     
         58        COUNT                                            ~43     !4
         59        DIV                                              ~44     $42, ~43
         60        ECHO                                                     ~44
         61      > RETURN                                                   1

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XZ5B2
function name:  __construct
number of ops:  4
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        ASSIGN_OBJ                                               'bar'
          2        OP_DATA                                                  !0
   29     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/XZ5B2
function name:  getBar
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   FETCH_OBJ_R                                      ~0      'bar'
          1      > RETURN                                                   ~0
   39     2*     > RETURN                                                   null

End of function getbar

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.81 ms | 1400 KiB | 17 Q