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 < 10; $t++) { $s = microtime(true); $obj = Test1::getInstance(); $s = microtime(true) - $s; $tests['Test1'][] = $s; } for ($t = 0; $t < 10; $t++) { $s = microtime(true); $obj = new Test2; var_dump(spl_object_hash($obj)); $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 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 22
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 22
Branch analysis from position: 46
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/o3JQ0
function name:  (null)
number of ops:  101
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, 10
         19      > JMPNZ                                                    ~15, ->2
   25    20    >   ASSIGN                                                   !0, 0
         21      > JMP                                                      ->44
   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                                               'var_dump'
         30        INIT_FCALL                                               'spl_object_hash'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                         $22     
         33        SEND_VAR                                                 $22
         34        DO_ICALL                                                 
   29    35        INIT_FCALL                                               'microtime'
         36        SEND_VAL                                                 <true>
         37        DO_ICALL                                         $24     
         38        SUB                                              ~25     $24, !1
         39        ASSIGN                                                   !1, ~25
   30    40        FETCH_DIM_W                                      $27     !3, 'Test2'
         41        ASSIGN_DIM                                               $27
         42        OP_DATA                                                  !1
   25    43        PRE_INC                                                  !0
         44    >   IS_SMALLER                                               !0, 10
         45      > JMPNZ                                                    ~30, ->22
   33    46    >   INIT_FCALL                                               'printf'
         47        SEND_VAL                                                 'Test1+first+result%3A+%25.9f+s%0A'
         48        INIT_FCALL                                               'array_shift'
         49        FETCH_DIM_W                                      $31     !3, 'Test1'
         50        SEND_REF                                                 $31
         51        DO_ICALL                                         $32     
         52        SEND_VAR                                                 $32
         53        DO_ICALL                                                 
   34    54        INIT_FCALL                                               'printf'
         55        SEND_VAL                                                 'Test1+last+result%3A+%25.9f+s%0A'
         56        INIT_FCALL                                               'array_pop'
         57        FETCH_DIM_W                                      $34     !3, 'Test1'
         58        SEND_REF                                                 $34
         59        DO_ICALL                                         $35     
         60        SEND_VAR                                                 $35
         61        DO_ICALL                                                 
   35    62        INIT_FCALL                                               'printf'
         63        SEND_VAL                                                 'Test2+first+result%3A+%25.9f+s%0A'
         64        INIT_FCALL                                               'array_shift'
         65        FETCH_DIM_W                                      $37     !3, 'Test2'
         66        SEND_REF                                                 $37
         67        DO_ICALL                                         $38     
         68        SEND_VAR                                                 $38
         69        DO_ICALL                                                 
   36    70        INIT_FCALL                                               'printf'
         71        SEND_VAL                                                 'Test2+last+result%3A+%25.9f+s%0A'
         72        INIT_FCALL                                               'array_pop'
         73        FETCH_DIM_W                                      $40     !3, 'Test2'
         74        SEND_REF                                                 $40
         75        DO_ICALL                                         $41     
         76        SEND_VAR                                                 $41
         77        DO_ICALL                                                 
   38    78        INIT_FCALL                                               'printf'
         79        SEND_VAL                                                 '%0ATest1+avg+result%3A+%25.9f+s%0A'
         80        INIT_FCALL                                               'array_sum'
         81        FETCH_DIM_R                                      ~43     !3, 'Test1'
         82        SEND_VAL                                                 ~43
         83        DO_ICALL                                         $44     
         84        FETCH_DIM_R                                      ~45     !3, 'Test1'
         85        COUNT                                            ~46     ~45
         86        DIV                                              ~47     $44, ~46
         87        SEND_VAL                                                 ~47
         88        DO_ICALL                                                 
   39    89        INIT_FCALL                                               'printf'
         90        SEND_VAL                                                 '%0ATest2+avg+result%3A+%25.9f+s%0A'
         91        INIT_FCALL                                               'array_sum'
         92        FETCH_DIM_R                                      ~49     !3, 'Test2'
         93        SEND_VAL                                                 ~49
         94        DO_ICALL                                         $50     
         95        FETCH_DIM_R                                      ~51     !3, 'Test2'
         96        COUNT                                            ~52     ~51
         97        DIV                                              ~53     $50, ~52
         98        SEND_VAL                                                 ~53
         99        DO_ICALL                                                 
        100      > RETURN                                                   1

Class Test1:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/o3JQ0
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/o3JQ0
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/o3JQ0
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:
159.87 ms | 1413 KiB | 27 Q