3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ArrayTester { const TEST_LOOP_SIZE = 1000000; public function go() { $start = microtime(true); for($a = 0; $a<=self::TEST_LOOP_SIZE;++$a) { $test = $this->getTest(); $someVal = $test[$a]; } echo 'Pass by copy: ' . (microtime(true) - $start) . ' sec<br>'; $start = microtime(true); for($a = 0; $a<=self::TEST_LOOP_SIZE;++$a) { $test = &$this->getTestByRef(); $someVal = $test[$a]; } echo 'Pass by reference: ' . (microtime(true) - $start) . ' sec<br>'; } private $_test; private function getTest() { if(!$this->_test) { for($a = 0; $a<=self::TEST_LOOP_SIZE;++$a) { $this->_test[$a]=md5($a); } } return $this->_test; } private $_testByRef; private function &getTestByRef() { if(!$this->_testByRef) { for($a = 0; $a<=self::TEST_LOOP_SIZE;++$a) { $this->_testByRef[$a]=md5($a); } } return $this->_testByRef; } } $tester = new ArrayTester(); $tester->go();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9WjBt
function name:  (null)
number of ops:  6
compiled vars:  !0 = $tester
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   NEW                                              $1      'ArrayTester'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   45     3        INIT_METHOD_CALL                                         !0, 'go'
          4        DO_FCALL                                      0          
          5      > RETURN                                                   1

Class ArrayTester:
Function go:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 27
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 27
Branch analysis from position: 35
Branch analysis from position: 27
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
Branch analysis from position: 6
filename:       /in/9WjBt
function name:  go
number of ops:  43
compiled vars:  !0 = $start, !1 = $a, !2 = $test, !3 = $someVal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 <true>
          2        DO_ICALL                                         $4      
          3        ASSIGN                                                   !0, $4
    9     4        ASSIGN                                                   !1, 0
          5      > JMP                                                      ->12
   10     6    >   INIT_METHOD_CALL                                         'getTest'
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !2, $7
   11     9        FETCH_DIM_R                                      ~9      !2, !1
         10        ASSIGN                                                   !3, ~9
    9    11        PRE_INC                                                  !1
         12    >   IS_SMALLER_OR_EQUAL                                      !1, 1000000
         13      > JMPNZ                                                    ~12, ->6
   13    14    >   INIT_FCALL                                               'microtime'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $13     
         17        SUB                                              ~14     $13, !0
         18        CONCAT                                           ~15     'Pass+by+copy%3A+', ~14
         19        CONCAT                                           ~16     ~15, '+sec%3Cbr%3E'
         20        ECHO                                                     ~16
   15    21        INIT_FCALL                                               'microtime'
         22        SEND_VAL                                                 <true>
         23        DO_ICALL                                         $17     
         24        ASSIGN                                                   !0, $17
   16    25        ASSIGN                                                   !1, 0
         26      > JMP                                                      ->33
   17    27    >   INIT_METHOD_CALL                                         'getTestByRef'
         28        DO_FCALL                                      0  $20     
         29        ASSIGN_REF                                               !2, $20
   18    30        FETCH_DIM_R                                      ~22     !2, !1
         31        ASSIGN                                                   !3, ~22
   16    32        PRE_INC                                                  !1
         33    >   IS_SMALLER_OR_EQUAL                                      !1, 1000000
         34      > JMPNZ                                                    ~25, ->27
   20    35    >   INIT_FCALL                                               'microtime'
         36        SEND_VAL                                                 <true>
         37        DO_ICALL                                         $26     
         38        SUB                                              ~27     $26, !0
         39        CONCAT                                           ~28     'Pass+by+reference%3A+', ~27
         40        CONCAT                                           ~29     ~28, '+sec%3Cbr%3E'
         41        ECHO                                                     ~29
   21    42      > RETURN                                                   null

End of function go

Function gettest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 5
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 5
Branch analysis from position: 14
Branch analysis from position: 5
Branch analysis from position: 14
filename:       /in/9WjBt
function name:  getTest
number of ops:  17
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   FETCH_OBJ_R                                      ~1      '_test'
          1        BOOL_NOT                                         ~2      ~1
          2      > JMPZ                                                     ~2, ->14
   26     3    >   ASSIGN                                                   !0, 0
          4      > JMP                                                      ->12
   27     5    >   INIT_FCALL                                               'md5'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $6      
          8        FETCH_OBJ_W                                      $4      '_test'
          9        ASSIGN_DIM                                               $4, !0
         10        OP_DATA                                                  $6
   26    11        PRE_INC                                                  !0
         12    >   IS_SMALLER_OR_EQUAL                                      !0, 1000000
         13      > JMPNZ                                                    ~8, ->5
   30    14    >   FETCH_OBJ_R                                      ~9      '_test'
         15      > RETURN                                                   ~9
   31    16*     > RETURN                                                   null

End of function gettest

Function gettestbyref:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 5
Branch analysis from position: 14
Return found
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 5
Branch analysis from position: 14
Branch analysis from position: 5
Branch analysis from position: 14
filename:       /in/9WjBt
function name:  getTestByRef
number of ops:  17
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   FETCH_OBJ_R                                      ~1      '_testByRef'
          1        BOOL_NOT                                         ~2      ~1
          2      > JMPZ                                                     ~2, ->14
   36     3    >   ASSIGN                                                   !0, 0
          4      > JMP                                                      ->12
   37     5    >   INIT_FCALL                                               'md5'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $6      
          8        FETCH_OBJ_W                                      $4      '_testByRef'
          9        ASSIGN_DIM                                               $4, !0
         10        OP_DATA                                                  $6
   36    11        PRE_INC                                                  !0
         12    >   IS_SMALLER_OR_EQUAL                                      !0, 1000000
         13      > JMPNZ                                                    ~8, ->5
   40    14    >   FETCH_OBJ_W                                      $9      '_testByRef'
         15      > RETURN_BY_REF                                            $9
   41    16*     > RETURN_BY_REF                                            null

End of function gettestbyref

End of class ArrayTester.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.31 ms | 1404 KiB | 17 Q