3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Instantiate object as singleton with private constructor class Test1 { protected static $instance; private function __construct() {} public static function getInstance() { return isset(static::$instance) ? static::$instance : static::$instance = new static; } } // Instantiate object from caller class Test2 { public function __construct() {} } for ($t = 0; $t < 10000; $t++) { $s = microtime(true); $obj = Test1::getInstance(); $s = microtime(true) - $s; $tests['Test1'][] = $s; } for ($t = 0; $t < 10000; $t++) { $s = microtime(true); $obj = new Test2; $s = microtime(true) - $s; $tests['Test2'][] = $s; } printf("Test1 first result: %.9f s\n", array_shift($tests['Test1'])); printf("Test1 last result: %.9f s\n", array_pop($tests['Test1'])); printf("Test2 first result: %.9f s\n", array_shift($tests['Test2'])); printf("Test2 last result: %.9f s\n", array_pop($tests['Test2'])); printf("\nTest1 avg result: %.9f s\n", array_sum($tests['Test1']) / count($tests['Test1'])); printf("\nTest2 avg result: %.9f s\n", array_sum($tests['Test2']) / count($tests['Test2']));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 2
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 22
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 22
Branch analysis from position: 40
Branch analysis from position: 22
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 2
Branch analysis from position: 20
Branch analysis from position: 2
filename:       /in/jhp2o
function name:  (null)
number of ops:  95
compiled vars:  !0 = $t, !1 = $s, !2 = $obj, !3 = $tests
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->18
   19     2    >   INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   20     6        INIT_STATIC_METHOD_CALL                                  'Test1', 'getInstance'
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !2, $7
   21     9        INIT_FCALL                                               'microtime'
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $9      
         12        SUB                                              ~10     $9, !1
         13        ASSIGN                                                   !1, ~10
   22    14        FETCH_DIM_W                                      $12     !3, 'Test1'
         15        ASSIGN_DIM                                               $12
         16        OP_DATA                                                  !1
   18    17        PRE_INC                                                  !0
         18    >   IS_SMALLER                                               !0, 10000
         19      > JMPNZ                                                    ~15, ->2
   25    20    >   ASSIGN                                                   !0, 0
         21      > JMP                                                      ->38
   26    22    >   INIT_FCALL                                               'microtime'
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $17     
         25        ASSIGN                                                   !1, $17
   27    26        NEW                                              $19     'Test2'
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !2, $19
   28    29        INIT_FCALL                                               'microtime'
         30        SEND_VAL                                                 <true>
         31        DO_ICALL                                         $22     
         32        SUB                                              ~23     $22, !1
         33        ASSIGN                                                   !1, ~23
   29    34        FETCH_DIM_W                                      $25     !3, 'Test2'
         35        ASSIGN_DIM                                               $25
         36        OP_DATA                                                  !1
   25    37        PRE_INC                                                  !0
         38    >   IS_SMALLER                                               !0, 10000
         39      > JMPNZ                                                    ~28, ->22
   32    40    >   INIT_FCALL                                               'printf'
         41        SEND_VAL                                                 'Test1+first+result%3A+%25.9f+s%0A'
         42        INIT_FCALL                                               'array_shift'
         43        FETCH_DIM_W                                      $29     !3, 'Test1'
         44        SEND_REF                                                 $29
         45        DO_ICALL                                         $30     
         46        SEND_VAR                                                 $30
         47        DO_ICALL                                                 
   33    48        INIT_FCALL                                               'printf'
         49        SEND_VAL                                                 'Test1+last+result%3A+%25.9f+s%0A'
         50        INIT_FCALL                                               'array_pop'
         51        FETCH_DIM_W                                      $32     !3, 'Test1'
         52        SEND_REF                                                 $32
         53        DO_ICALL                                         $33     
         54        SEND_VAR                                                 $33
         55        DO_ICALL                                                 
   34    56        INIT_FCALL                                               'printf'
         57        SEND_VAL                                                 'Test2+first+result%3A+%25.9f+s%0A'
         58        INIT_FCALL                                               'array_shift'
         59        FETCH_DIM_W                                      $35     !3, 'Test2'
         60        SEND_REF                                                 $35
         61        DO_ICALL                                         $36     
         62        SEND_VAR                                                 $36
         63        DO_ICALL                                                 
   35    64        INIT_FCALL                                               'printf'
         65        SEND_VAL                                                 'Test2+last+result%3A+%25.9f+s%0A'
         66        INIT_FCALL                                               'array_pop'
         67        FETCH_DIM_W                                      $38     !3, 'Test2'
         68        SEND_REF                                                 $38
         69        DO_ICALL                                         $39     
         70        SEND_VAR                                                 $39
         71        DO_ICALL                                                 
   37    72        INIT_FCALL                                               'printf'
         73        SEND_VAL                                                 '%0ATest1+avg+result%3A+%25.9f+s%0A'
         74        INIT_FCALL                                               'array_sum'
         75        FETCH_DIM_R                                      ~41     !3, 'Test1'
         76        SEND_VAL                                                 ~41
         77        DO_ICALL                                         $42     
         78        FETCH_DIM_R                                      ~43     !3, 'Test1'
         79        COUNT                                            ~44     ~43
         80        DIV                                              ~45     $42, ~44
         81        SEND_VAL                                                 ~45
         82        DO_ICALL                                                 
   38    83        INIT_FCALL                                               'printf'
         84        SEND_VAL                                                 '%0ATest2+avg+result%3A+%25.9f+s%0A'
         85        INIT_FCALL                                               'array_sum'
         86        FETCH_DIM_R                                      ~47     !3, 'Test2'
         87        SEND_VAL                                                 ~47
         88        DO_ICALL                                         $48     
         89        FETCH_DIM_R                                      ~49     !3, 'Test2'
         90        COUNT                                            ~50     ~49
         91        DIV                                              ~51     $48, ~50
         92        SEND_VAL                                                 ~51
         93        DO_ICALL                                                 
         94      > RETURN                                                   1

Class Test1:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jhp2o
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E > > RETURN                                                   null

End of function __construct

Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 5
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jhp2o
function name:  getInstance
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   ISSET_ISEMPTY_STATIC_PROP                                'instance'
          1      > JMPZ                                                     ~0, ->5
          2    >   FETCH_STATIC_PROP_R          unknown             ~1      'instance'
          3        QM_ASSIGN                                        ~2      ~1
          4      > JMP                                                      ->10
          5    >   NEW                          static              $4      
          6        DO_FCALL                                      0          
          7        ASSIGN_STATIC_PROP                               ~3      'instance'
          8        OP_DATA                                                  $4
          9        QM_ASSIGN                                        ~2      ~3
         10    > > RETURN                                                   ~2
   10    11*     > RETURN                                                   null

End of function getinstance

End of class Test1.

Class Test2:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jhp2o
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E > > RETURN                                                   null

End of function __construct

End of class Test2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.94 ms | 1404 KiB | 23 Q