3v4l.org

run code in 300+ PHP versions simultaneously
<?php const N = 1000; class Redis { public function run($n) { $a = rand($n, 2*$n); } } class A { protected $redis; function __construct() { $this->redis = new Redis(); } function getRedis() { return $this->redis; } function run() { for ($i = 0; $i < N; $i++) { $this->getRedis()->run($i); } } } class B { protected $redis; function __construct() { $this->redis = new Redis(); } function run() { for ($i = 0; $i < N; $i++) { $this->redis->run($i); } } } $time = microtime(true); (new A())->run(); $et1 = microtime(true) - $time; print 'Execution time with *property* accessor: ' . $et1 . PHP_EOL; $time = microtime(true); (new B())->run(); $et2 = microtime(true) - $time; print 'Execution time *without* property accessor: ' . $et2 . PHP_EOL; print 'Ratio: ' . ($et1/$et2) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dcsZK
function name:  (null)
number of ops:  38
compiled vars:  !0 = $time, !1 = $et1, !2 = $et2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_CONST                                            'N', 1000
   58     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
   60     5        NEW                                              $5      'A'
          6        DO_FCALL                                      0          
          7        INIT_METHOD_CALL                                         $5, 'run'
          8        DO_FCALL                                      0          
   62     9        INIT_FCALL                                               'microtime'
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $8      
         12        SUB                                              ~9      $8, !0
         13        ASSIGN                                                   !1, ~9
   64    14        CONCAT                                           ~11     'Execution+time+with+%2Aproperty%2A+accessor%3A+', !1
         15        CONCAT                                           ~12     ~11, '%0A'
         16        ECHO                                                     ~12
   68    17        INIT_FCALL                                               'microtime'
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $13     
         20        ASSIGN                                                   !0, $13
   70    21        NEW                                              $15     'B'
         22        DO_FCALL                                      0          
         23        INIT_METHOD_CALL                                         $15, 'run'
         24        DO_FCALL                                      0          
   72    25        INIT_FCALL                                               'microtime'
         26        SEND_VAL                                                 <true>
         27        DO_ICALL                                         $18     
         28        SUB                                              ~19     $18, !0
         29        ASSIGN                                                   !2, ~19
   74    30        CONCAT                                           ~21     'Execution+time+%2Awithout%2A+property+accessor%3A+', !2
         31        CONCAT                                           ~22     ~21, '%0A'
         32        ECHO                                                     ~22
   77    33        DIV                                              ~23     !1, !2
         34        CONCAT                                           ~24     'Ratio%3A+', ~23
         35        CONCAT                                           ~25     ~24, '%0A'
         36        ECHO                                                     ~25
         37      > RETURN                                                   1

Class Redis:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dcsZK
function name:  run
number of ops:  8
compiled vars:  !0 = $n, !1 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'rand'
          2        SEND_VAR                                                 !0
          3        MUL                                              ~2      !0, 2
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !1, $3
   11     7      > RETURN                                                   null

End of function run

End of class Redis.

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dcsZK
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                                              $1      'Redis'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'redis'
          3        OP_DATA                                                  $1
   21     4      > RETURN                                                   null

End of function __construct

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

End of function getredis

Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 2
Branch analysis from position: 11
Branch analysis from position: 2
filename:       /in/dcsZK
function name:  run
number of ops:  12
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->8
   32     2    >   INIT_METHOD_CALL                                         'getRedis'
          3        DO_FCALL                                      0  $2      
          4        INIT_METHOD_CALL                                         $2, 'run'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   31     7        PRE_INC                                                  !0
          8    >   FETCH_CONSTANT                                   ~5      'N'
          9        IS_SMALLER                                               !0, ~5
         10      > JMPNZ                                                    ~6, ->2
   34    11    > > RETURN                                                   null

End of function run

End of class A.

Class B:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dcsZK
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   NEW                                              $1      'Redis'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'redis'
          3        OP_DATA                                                  $1
   45     4      > RETURN                                                   null

End of function __construct

Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 2
Branch analysis from position: 10
Branch analysis from position: 2
filename:       /in/dcsZK
function name:  run
number of ops:  11
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->7
   51     2    >   FETCH_OBJ_R                                      ~2      'redis'
          3        INIT_METHOD_CALL                                         ~2, 'run'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
   50     6        PRE_INC                                                  !0
          7    >   FETCH_CONSTANT                                   ~5      'N'
          8        IS_SMALLER                                               !0, ~5
          9      > JMPNZ                                                    ~6, ->2
   53    10    > > RETURN                                                   null

End of function run

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.04 ms | 1404 KiB | 17 Q