3v4l.org

run code in 500+ PHP versions simultaneously
<?php function hinted(array $a, StdClass $b): int { return count($a); } function unhinted($a, $b) { return count($a); } $max = 10000000; $a = array(1,2,3,4); $b = new StdClass(); $b->foo = "bar"; // run unhinted test first to cause any possible cold startup effects to hit it more to make this as fair as possible for hinted code $start = microtime(true); for ($i=0; $i<$max; $i++) $rv = unhinted($a, $b); $elapsed_unhinted = microtime(true) - $start; printf("unhinted: Elapsed %.2f seconds\n", $elapsed_unhinted); $start = microtime(true); for ($i=0; $i<$max; $i++) $rv = hinted($a, $b); $elapsed_hinted = microtime(true) - $start; printf("hinted: Elapsed %.2f seconds\n", $elapsed_hinted); if ($elapsed_unhinted > 0) { $overhead = $elapsed_hinted / $elapsed_unhinted; if ($overhead <= 1.0) printf("No overhead for hinted signature, factor=%.2\n", $overhead); else printf("Type hinting causes %d %% overhead for small functions.\n", round(100*($overhead - 1.0))); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 13
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 36
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 73
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 64
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 36
Branch analysis from position: 44
Branch analysis from position: 36
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 13
Branch analysis from position: 21
Branch analysis from position: 13
filename:       /in/hOVBp
function name:  (null)
number of ops:  74
compiled vars:  !0 = $max, !1 = $a, !2 = $b, !3 = $start, !4 = $i, !5 = $rv, !6 = $elapsed_unhinted, !7 = $elapsed_hinted, !8 = $overhead
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                       !0, 10000000
   14     1        ASSIGN                                                       !1, <array>
   15     2        NEW                                                  $11     'StdClass'
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !2, $11
   16     5        ASSIGN_OBJ                                                   !2, 'foo'
          6        OP_DATA                                                      'bar'
   19     7        INIT_FCALL                                                   'microtime'
          8        SEND_VAL                                                     <true>
          9        DO_ICALL                                             $15     
         10        ASSIGN                                                       !3, $15
   20    11        ASSIGN                                                       !4, 0
         12      > JMP                                                          ->19
   21    13    >   INIT_FCALL                                                   'unhinted'
         14        SEND_VAR                                                     !1
         15        SEND_VAR                                                     !2
         16        DO_FCALL                                          0  $18     
         17        ASSIGN                                                       !5, $18
   20    18        PRE_INC                                                      !4
         19    >   IS_SMALLER                                                   !4, !0
         20      > JMPNZ                                                        ~21, ->13
   22    21    >   INIT_FCALL                                                   'microtime'
         22        SEND_VAL                                                     <true>
         23        DO_ICALL                                             $22     
         24        SUB                                                  ~23     $22, !3
         25        ASSIGN                                                       !6, ~23
   23    26        INIT_FCALL                                                   'printf'
         27        SEND_VAL                                                     'unhinted%3A+Elapsed+%25.2f+seconds%0A'
         28        SEND_VAR                                                     !6
         29        DO_ICALL                                                     
   25    30        INIT_FCALL                                                   'microtime'
         31        SEND_VAL                                                     <true>
         32        DO_ICALL                                             $26     
         33        ASSIGN                                                       !3, $26
   26    34        ASSIGN                                                       !4, 0
         35      > JMP                                                          ->42
   27    36    >   INIT_FCALL                                                   'hinted'
         37        SEND_VAR                                                     !1
         38        SEND_VAR                                                     !2
         39        DO_FCALL                                          0  $29     
         40        ASSIGN                                                       !5, $29
   26    41        PRE_INC                                                      !4
         42    >   IS_SMALLER                                                   !4, !0
         43      > JMPNZ                                                        ~32, ->36
   28    44    >   INIT_FCALL                                                   'microtime'
         45        SEND_VAL                                                     <true>
         46        DO_ICALL                                             $33     
         47        SUB                                                  ~34     $33, !3
         48        ASSIGN                                                       !7, ~34
   29    49        INIT_FCALL                                                   'printf'
         50        SEND_VAL                                                     'hinted%3A+Elapsed+%25.2f+seconds%0A'
         51        SEND_VAR                                                     !7
         52        DO_ICALL                                                     
   31    53        IS_SMALLER                                                   0, !6
         54      > JMPZ                                                         ~37, ->73
   33    55    >   DIV                                                  ~38     !7, !6
         56        ASSIGN                                                       !8, ~38
   34    57        IS_SMALLER_OR_EQUAL                                          !8, 1
         58      > JMPZ                                                         ~40, ->64
   35    59    >   INIT_FCALL                                                   'printf'
         60        SEND_VAL                                                     'No+overhead+for+hinted+signature%2C+factor%3D%25.2%0A'
         61        SEND_VAR                                                     !8
         62        DO_ICALL                                                     
   34    63      > JMP                                                          ->73
   37    64    >   INIT_FCALL                                                   'printf'
         65        SEND_VAL                                                     'Type+hinting+causes+%25d+%25%25+overhead+for+small+functions.%0A'
         66        INIT_FCALL                                                   'round'
         67        SUB                                                  ~42     !8, 1
         68        MUL                                                  ~43     ~42, 100
         69        SEND_VAL                                                     ~43
         70        DO_ICALL                                             $44     
         71        SEND_VAR                                                     $44
         72        DO_ICALL                                                     
   38    73    > > RETURN                                                       1

Function hinted:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hOVBp
function name:  hinted
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        COUNT                                                ~2      !0
          3        VERIFY_RETURN_TYPE                                           ~2
          4      > RETURN                                                       ~2
    6     5*       VERIFY_RETURN_TYPE                                           
          6*     > RETURN                                                       null

End of function hinted

Function unhinted:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hOVBp
function name:  unhinted
number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   10     2        COUNT                                                ~2      !0
          3      > RETURN                                                       ~2
   11     4*     > RETURN                                                       null

End of function unhinted

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.98 ms | 1826 KiB | 18 Q