3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public static function test() { return true; } } function test() { static $a; return $a ??= new A; } $its = 1e3; $test = test(); $t = hrtime(true); for ( $i=0;$i++<$its;) test()->test(); echo (hrtime(true)-$t)/1e9,"s\n"; $t = hrtime(true); for ( $i=0;$i++<$its;) $test->test(); echo (hrtime(true)-$t)/1e9,"s\n"; $t = hrtime(true); for ( $i=0;$i++<$its;) A::test(); echo (hrtime(true)-$t)/1e9,"s\n"; echo "\n=== Warmed up ===\n\n"; $its = 1e6; $t = hrtime(true); for ( $i=0;$i++<$its;) test()->test(); echo $a=(hrtime(true)-$t)/1e9,"s\n"; $t = hrtime(true); for ( $i=0;$i++<$its;) $test->test(); echo $b=(hrtime(true)-$t)/1e9,"s\n"; $t = hrtime(true); for ( $i=0;$i++<$its;) A::test(); echo $c=(hrtime(true)-$t)/1e9,"s\n"; echo number_format((($a-$c)/$a) * 100, 2 ), "% faster from function\n"; echo number_format((($b-$c)/$b) * 100, 2 ), "% faster from variable\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 10
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 30
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 48
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 68
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
2 jumps found. (Code = 44) Position 1 = 94, Position 2 = 89
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 110
Branch analysis from position: 110
2 jumps found. (Code = 44) Position 1 = 113, Position 2 = 108
Branch analysis from position: 113
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 108
2 jumps found. (Code = 44) Position 1 = 113, Position 2 = 108
Branch analysis from position: 113
Branch analysis from position: 108
Branch analysis from position: 89
2 jumps found. (Code = 44) Position 1 = 94, Position 2 = 89
Branch analysis from position: 94
Branch analysis from position: 89
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 68
Branch analysis from position: 75
Branch analysis from position: 68
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 48
Branch analysis from position: 53
Branch analysis from position: 48
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 30
Branch analysis from position: 35
Branch analysis from position: 30
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 10
Branch analysis from position: 17
Branch analysis from position: 10
filename:       /in/J00A0
function name:  (null)
number of ops:  140
compiled vars:  !0 = $its, !1 = $test, !2 = $t, !3 = $i, !4 = $a, !5 = $b, !6 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, 1000
   16     1        INIT_FCALL                                               'test'
          2        DO_FCALL                                      0  $8      
          3        ASSIGN                                                   !1, $8
   18     4        INIT_FCALL                                               'hrtime'
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !2, $10
   19     8        ASSIGN                                                   !3, 0
          9      > JMP                                                      ->14
   20    10    >   INIT_FCALL                                               'test'
         11        DO_FCALL                                      0  $13     
         12        INIT_METHOD_CALL                                         $13, 'test'
         13        DO_FCALL                                      0          
   19    14    >   POST_INC                                         ~15     !3
         15        IS_SMALLER                                               ~15, !0
         16      > JMPNZ                                                    ~16, ->10
   21    17    >   INIT_FCALL                                               'hrtime'
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $17     
         20        SUB                                              ~18     $17, !2
         21        DIV                                              ~19     ~18, 1.0e+9
         22        ECHO                                                     ~19
         23        ECHO                                                     's%0A'
   23    24        INIT_FCALL                                               'hrtime'
         25        SEND_VAL                                                 <true>
         26        DO_ICALL                                         $20     
         27        ASSIGN                                                   !2, $20
   24    28        ASSIGN                                                   !3, 0
         29      > JMP                                                      ->32
   25    30    >   INIT_METHOD_CALL                                         !1, 'test'
         31        DO_FCALL                                      0          
   24    32    >   POST_INC                                         ~24     !3
         33        IS_SMALLER                                               ~24, !0
         34      > JMPNZ                                                    ~25, ->30
   26    35    >   INIT_FCALL                                               'hrtime'
         36        SEND_VAL                                                 <true>
         37        DO_ICALL                                         $26     
         38        SUB                                              ~27     $26, !2
         39        DIV                                              ~28     ~27, 1.0e+9
         40        ECHO                                                     ~28
         41        ECHO                                                     's%0A'
   28    42        INIT_FCALL                                               'hrtime'
         43        SEND_VAL                                                 <true>
         44        DO_ICALL                                         $29     
         45        ASSIGN                                                   !2, $29
   29    46        ASSIGN                                                   !3, 0
         47      > JMP                                                      ->50
   30    48    >   INIT_STATIC_METHOD_CALL                                  'A', 'test'
         49        DO_FCALL                                      0          
   29    50    >   POST_INC                                         ~33     !3
         51        IS_SMALLER                                               ~33, !0
         52      > JMPNZ                                                    ~34, ->48
   31    53    >   INIT_FCALL                                               'hrtime'
         54        SEND_VAL                                                 <true>
         55        DO_ICALL                                         $35     
         56        SUB                                              ~36     $35, !2
         57        DIV                                              ~37     ~36, 1.0e+9
         58        ECHO                                                     ~37
         59        ECHO                                                     's%0A'
   33    60        ECHO                                                     '%0A%3D%3D%3D+Warmed+up+%3D%3D%3D%0A%0A'
   35    61        ASSIGN                                                   !0, 1.0e+6
   37    62        INIT_FCALL                                               'hrtime'
         63        SEND_VAL                                                 <true>
         64        DO_ICALL                                         $39     
         65        ASSIGN                                                   !2, $39
   38    66        ASSIGN                                                   !3, 0
         67      > JMP                                                      ->72
   39    68    >   INIT_FCALL                                               'test'
         69        DO_FCALL                                      0  $42     
         70        INIT_METHOD_CALL                                         $42, 'test'
         71        DO_FCALL                                      0          
   38    72    >   POST_INC                                         ~44     !3
         73        IS_SMALLER                                               ~44, !0
         74      > JMPNZ                                                    ~45, ->68
   40    75    >   INIT_FCALL                                               'hrtime'
         76        SEND_VAL                                                 <true>
         77        DO_ICALL                                         $46     
         78        SUB                                              ~47     $46, !2
         79        DIV                                              ~48     ~47, 1.0e+9
         80        ASSIGN                                           ~49     !4, ~48
         81        ECHO                                                     ~49
         82        ECHO                                                     's%0A'
   42    83        INIT_FCALL                                               'hrtime'
         84        SEND_VAL                                                 <true>
         85        DO_ICALL                                         $50     
         86        ASSIGN                                                   !2, $50
   43    87        ASSIGN                                                   !3, 0
         88      > JMP                                                      ->91
   44    89    >   INIT_METHOD_CALL                                         !1, 'test'
         90        DO_FCALL                                      0          
   43    91    >   POST_INC                                         ~54     !3
         92        IS_SMALLER                                               ~54, !0
         93      > JMPNZ                                                    ~55, ->89
   45    94    >   INIT_FCALL                                               'hrtime'
         95        SEND_VAL                                                 <true>
         96        DO_ICALL                                         $56     
         97        SUB                                              ~57     $56, !2
         98        DIV                                              ~58     ~57, 1.0e+9
         99        ASSIGN                                           ~59     !5, ~58
        100        ECHO                                                     ~59
        101        ECHO                                                     's%0A'
   47   102        INIT_FCALL                                               'hrtime'
        103        SEND_VAL                                                 <true>
        104        DO_ICALL                                         $60     
        105        ASSIGN                                                   !2, $60
   48   106        ASSIGN                                                   !3, 0
        107      > JMP                                                      ->110
   49   108    >   INIT_STATIC_METHOD_CALL                                  'A', 'test'
        109        DO_FCALL                                      0          
   48   110    >   POST_INC                                         ~64     !3
        111        IS_SMALLER                                               ~64, !0
        112      > JMPNZ                                                    ~65, ->108
   50   113    >   INIT_FCALL                                               'hrtime'
        114        SEND_VAL                                                 <true>
        115        DO_ICALL                                         $66     
        116        SUB                                              ~67     $66, !2
        117        DIV                                              ~68     ~67, 1.0e+9
        118        ASSIGN                                           ~69     !6, ~68
        119        ECHO                                                     ~69
        120        ECHO                                                     's%0A'
   52   121        INIT_FCALL                                               'number_format'
        122        SUB                                              ~70     !4, !6
        123        DIV                                              ~71     ~70, !4
        124        MUL                                              ~72     ~71, 100
        125        SEND_VAL                                                 ~72
        126        SEND_VAL                                                 2
        127        DO_ICALL                                         $73     
        128        ECHO                                                     $73
        129        ECHO                                                     '%25+faster+from+function%0A'
   53   130        INIT_FCALL                                               'number_format'
        131        SUB                                              ~74     !5, !6
        132        DIV                                              ~75     ~74, !5
        133        MUL                                              ~76     ~75, 100
        134        SEND_VAL                                                 ~76
        135        SEND_VAL                                                 2
        136        DO_ICALL                                         $77     
        137        ECHO                                                     $77
        138        ECHO                                                     '%25+faster+from+variable%0A'
        139      > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J00A0
function name:  test
number of ops:  8
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   BIND_STATIC                                              !0
   11     1        COALESCE                                         ~1      !0
          2        NEW                                              $2      'A'
          3        DO_FCALL                                      0          
          4        ASSIGN                                           ~4      !0, $2
          5        QM_ASSIGN                                        ~1      ~4
          6      > RETURN                                                   ~1
   12     7*     > RETURN                                                   null

End of function test

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

End of function test

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
131.91 ms | 1415 KiB | 20 Q