3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('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); $a = new A(); $a->run(); $et1 = microtime(true) - $time; print 'Execution time with *property* accessor: ' . $et1 . PHP_EOL; $time = microtime(true); $b = new B(); $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/26pWJ
function name:  (null)
number of ops:  43
compiled vars:  !0 = $time, !1 = $a, !2 = $et1, !3 = $b, !4 = $et2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'N'
          2        SEND_VAL                                                 1000
          3        DO_ICALL                                                 
   58     4        INIT_FCALL                                               'microtime'
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !0, $6
   60     8        NEW                                              $8      'A'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $8
   61    11        INIT_METHOD_CALL                                         !1, 'run'
         12        DO_FCALL                                      0          
   63    13        INIT_FCALL                                               'microtime'
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $12     
         16        SUB                                              ~13     $12, !0
         17        ASSIGN                                                   !2, ~13
   65    18        CONCAT                                           ~15     'Execution+time+with+%2Aproperty%2A+accessor%3A+', !2
         19        CONCAT                                           ~16     ~15, '%0A'
         20        ECHO                                                     ~16
   69    21        INIT_FCALL                                               'microtime'
         22        SEND_VAL                                                 <true>
         23        DO_ICALL                                         $17     
         24        ASSIGN                                                   !0, $17
   71    25        NEW                                              $19     'B'
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !3, $19
   72    28        INIT_METHOD_CALL                                         !3, 'run'
         29        DO_FCALL                                      0          
   74    30        INIT_FCALL                                               'microtime'
         31        SEND_VAL                                                 <true>
         32        DO_ICALL                                         $23     
         33        SUB                                              ~24     $23, !0
         34        ASSIGN                                                   !4, ~24
   76    35        CONCAT                                           ~26     'Execution+time+%2Awithout%2A+property+accessor%3A+', !4
         36        CONCAT                                           ~27     ~26, '%0A'
         37        ECHO                                                     ~27
   79    38        DIV                                              ~28     !2, !4
         39        CONCAT                                           ~29     'Ratio%3A+', ~28
         40        CONCAT                                           ~30     ~29, '%0A'
         41        ECHO                                                     ~30
         42      > RETURN                                                   1

Class Redis:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/26pWJ
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/26pWJ
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/26pWJ
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/26pWJ
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/26pWJ
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/26pWJ
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:
149.4 ms | 1404 KiB | 19 Q