3v4l.org

run code in 300+ PHP versions simultaneously
<?php function report($name, $time) { static $last = null; printf("%-12s: %.8fms", $name, $time); if (null !== $last) { printf(", %.1f%%", (($time - $last)/$last)*100); } echo PHP_EOL; $last = $time; } $iterations = 100000; $a = str_repeat('a', 2<<8); $times = array( "direct" => 0, "static" => 0, "object" => 0 ); class Os { public static function strcmp($a) { strcmp($a, $a); } } class Om { public function strcmp($a) { strcmp($a, $a); } } $o = new Om(); for ($x=0; $x<$iterations; $x++) { $start = microtime(true); strcmp($a, $a); $end = microtime(true) - $start; $times["direct"]+= $end; $start = microtime(true); Os::strcmp($a); $end = microtime(true) - $start; $times["static"]+= $end; $start = microtime(true); $o->strcmp($a); $end = microtime(true) - $start; $times["object"]+= $end; } foreach ($times as $name => $time) { report($name, ($time/$iterations)*1000); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 12
Branch analysis from position: 58
2 jumps found. (Code = 77) Position 1 = 59, Position 2 = 68
Branch analysis from position: 59
2 jumps found. (Code = 78) Position 1 = 60, Position 2 = 68
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 12
Branch analysis from position: 58
Branch analysis from position: 12
filename:       /in/biM9G
function name:  (null)
number of ops:  70
compiled vars:  !0 = $iterations, !1 = $a, !2 = $times, !3 = $o, !4 = $x, !5 = $start, !6 = $end, !7 = $time, !8 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, 100000
   15     1        INIT_FCALL                                               'str_repeat'
          2        SEND_VAL                                                 'a'
          3        SEND_VAL                                                 512
          4        DO_ICALL                                         $10     
          5        ASSIGN                                                   !1, $10
   17     6        ASSIGN                                                   !2, <array>
   34     7        NEW                                              $13     'Om'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $13
   36    10        ASSIGN                                                   !4, 0
         11      > JMP                                                      ->56
   38    12    >   INIT_FCALL                                               'microtime'
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $17     
         15        ASSIGN                                                   !5, $17
   39    16        INIT_FCALL                                               'strcmp'
         17        SEND_VAR                                                 !1
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
   40    20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $20     
         23        SUB                                              ~21     $20, !5
         24        ASSIGN                                                   !6, ~21
   41    25        ASSIGN_DIM_OP                +=               1          !2, 'direct'
         26        OP_DATA                                                  !6
   43    27        INIT_FCALL                                               'microtime'
         28        SEND_VAL                                                 <true>
         29        DO_ICALL                                         $24     
         30        ASSIGN                                                   !5, $24
   44    31        INIT_STATIC_METHOD_CALL                                  'Os', 'strcmp'
         32        SEND_VAR                                                 !1
         33        DO_FCALL                                      0          
   45    34        INIT_FCALL                                               'microtime'
         35        SEND_VAL                                                 <true>
         36        DO_ICALL                                         $27     
         37        SUB                                              ~28     $27, !5
         38        ASSIGN                                                   !6, ~28
   46    39        ASSIGN_DIM_OP                +=               1          !2, 'static'
         40        OP_DATA                                                  !6
   48    41        INIT_FCALL                                               'microtime'
         42        SEND_VAL                                                 <true>
         43        DO_ICALL                                         $31     
         44        ASSIGN                                                   !5, $31
   49    45        INIT_METHOD_CALL                                         !3, 'strcmp'
         46        SEND_VAR_EX                                              !1
         47        DO_FCALL                                      0          
   50    48        INIT_FCALL                                               'microtime'
         49        SEND_VAL                                                 <true>
         50        DO_ICALL                                         $34     
         51        SUB                                              ~35     $34, !5
         52        ASSIGN                                                   !6, ~35
   51    53        ASSIGN_DIM_OP                +=               1          !2, 'object'
         54        OP_DATA                                                  !6
   36    55        PRE_INC                                                  !4
         56    >   IS_SMALLER                                               !4, !0
         57      > JMPNZ                                                    ~39, ->12
   54    58    > > FE_RESET_R                                       $40     !2, ->68
         59    > > FE_FETCH_R                                       ~41     $40, !7, ->68
         60    >   ASSIGN                                                   !8, ~41
   55    61        INIT_FCALL                                               'report'
         62        SEND_VAR                                                 !8
         63        DIV                                              ~43     !7, !0
         64        MUL                                              ~44     ~43, 1000
         65        SEND_VAL                                                 ~44
         66        DO_FCALL                                      0          
   54    67      > JMP                                                      ->59
         68    >   FE_FREE                                                  $40
   56    69      > RETURN                                                   1

Function report:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/biM9G
function name:  report
number of ops:  20
compiled vars:  !0 = $name, !1 = $time, !2 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        BIND_STATIC                                              !2
    5     3        INIT_FCALL                                               'printf'
          4        SEND_VAL                                                 '%25-12s%3A+%25.8fms'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
    6     8        TYPE_CHECK                                  1020          !2
          9      > JMPZ                                                     ~4, ->17
    7    10    >   INIT_FCALL                                               'printf'
         11        SEND_VAL                                                 '%2C+%25.1f%25%25'
         12        SUB                                              ~5      !1, !2
         13        DIV                                              ~6      ~5, !2
         14        MUL                                              ~7      ~6, 100
         15        SEND_VAL                                                 ~7
         16        DO_ICALL                                                 
    9    17    >   ECHO                                                     '%0A'
   10    18        ASSIGN                                                   !2, !1
   11    19      > RETURN                                                   null

End of function report

Class Os:
Function strcmp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/biM9G
function name:  strcmp
number of ops:  6
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'strcmp'
          2        SEND_VAR                                                 !0
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   26     5      > RETURN                                                   null

End of function strcmp

End of class Os.

Class Om:
Function strcmp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/biM9G
function name:  strcmp
number of ops:  6
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_FCALL                                               'strcmp'
          2        SEND_VAR                                                 !0
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   31     5      > RETURN                                                   null

End of function strcmp

End of class Om.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.66 ms | 1012 KiB | 18 Q