3v4l.org

run code in 300+ PHP versions simultaneously
<?php // run the callback a lot, return average run time in ms function clock(\Closure $callback, $iterations = 100000) { $begin = microtime(true); for ($i = 0; $i < $iterations; $i++) { $callback(); } $end = microtime(true) - $begin; return ($end / $iterations)*1000; } // nicely show me how long the name ran, and percent increase/decrease over last 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; } // fixtures $a = str_repeat('a', 2<<8); class Os { public static function strcmp($a) { strcmp($a, $a); } } class Om { public function strcmp($a) { strcmp($a, $a); } } // do it report('direct call', clock(function () use ($a) { strcmp($a, $a); })); report('static call', clock(function () use ($a) { Os::strcmp($a); })); report('object call', clock(function () use ($a) { $o = new Om(); $o->strcmp($a); })); report('voodoo call', clock(function () use ($a) { $o = unserialize('O:2:"Om":0:{}'); $o->strcmp($a); }));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NsjJR
function name:  (null)
number of ops:  42
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'str_repeat'
          1        SEND_VAL                                                 'a'
          2        SEND_VAL                                                 512
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   35     5        INIT_FCALL                                               'report'
          6        SEND_VAL                                                 'direct+call'
          7        INIT_FCALL                                               'clock'
          8        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          9        BIND_LEXICAL                                             ~3, !0
         10        SEND_VAL                                                 ~3
         11        DO_FCALL                                      0  $4      
         12        SEND_VAR                                                 $4
         13        DO_FCALL                                      0          
   36    14        INIT_FCALL                                               'report'
         15        SEND_VAL                                                 'static+call'
         16        INIT_FCALL                                               'clock'
         17        DECLARE_LAMBDA_FUNCTION                          ~6      [1]
         18        BIND_LEXICAL                                             ~6, !0
         19        SEND_VAL                                                 ~6
         20        DO_FCALL                                      0  $7      
         21        SEND_VAR                                                 $7
         22        DO_FCALL                                      0          
   37    23        INIT_FCALL                                               'report'
         24        SEND_VAL                                                 'object+call'
         25        INIT_FCALL                                               'clock'
         26        DECLARE_LAMBDA_FUNCTION                          ~9      [2]
         27        BIND_LEXICAL                                             ~9, !0
         28        SEND_VAL                                                 ~9
         29        DO_FCALL                                      0  $10     
         30        SEND_VAR                                                 $10
         31        DO_FCALL                                      0          
   38    32        INIT_FCALL                                               'report'
         33        SEND_VAL                                                 'voodoo+call'
         34        INIT_FCALL                                               'clock'
         35        DECLARE_LAMBDA_FUNCTION                          ~12     [3]
         36        BIND_LEXICAL                                             ~12, !0
         37        SEND_VAL                                                 ~12
         38        DO_FCALL                                      0  $13     
         39        SEND_VAR                                                 $13
         40        DO_FCALL                                      0          
         41      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NsjJR
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   BIND_STATIC                                              !0
          1        INIT_FCALL                                               'strcmp'
          2        SEND_VAR                                                 !0
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
          5      > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NsjJR
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   BIND_STATIC                                              !0
          1        INIT_STATIC_METHOD_CALL                                  'Os', 'strcmp'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NsjJR
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $a, !1 = $o
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   BIND_STATIC                                              !0
          1        NEW                                              $2      'Om'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
          4        INIT_METHOD_CALL                                         !1, 'strcmp'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7      > RETURN                                                   null

End of Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NsjJR
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $a, !1 = $o
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   BIND_STATIC                                              !0
          1        INIT_FCALL                                               'unserialize'
          2        SEND_VAL                                                 'O%3A2%3A%22Om%22%3A0%3A%7B%7D'
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
          5        INIT_METHOD_CALL                                         !1, 'strcmp'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8      > RETURN                                                   null

End of Dynamic Function 3

Function clock:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
Branch analysis from position: 8
filename:       /in/NsjJR
function name:  clock
number of ops:  22
compiled vars:  !0 = $callback, !1 = $iterations, !2 = $begin, !3 = $i, !4 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      100000
    5     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !2, $5
    7     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->11
    8     8    >   INIT_DYNAMIC_CALL                                        !0
          9        DO_FCALL                                      0          
    7    10        PRE_INC                                                  !3
         11    >   IS_SMALLER                                               !3, !1
         12      > JMPNZ                                                    ~10, ->8
   11    13    >   INIT_FCALL                                               'microtime'
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $11     
         16        SUB                                              ~12     $11, !2
         17        ASSIGN                                                   !4, ~12
   13    18        DIV                                              ~14     !4, !1
         19        MUL                                              ~15     ~14, 1000
         20      > RETURN                                                   ~15
   14    21*     > RETURN                                                   null

End of function clock

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/NsjJR
function name:  report
number of ops:  20
compiled vars:  !0 = $name, !1 = $time, !2 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        BIND_STATIC                                              !2
   19     3        INIT_FCALL                                               'printf'
          4        SEND_VAL                                                 '%25-12s%3A+%25.8fms'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
   20     8        TYPE_CHECK                                  1020          !2
          9      > JMPZ                                                     ~4, ->17
   21    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                                                 
   23    17    >   ECHO                                                     '%0A'
   24    18        ASSIGN                                                   !2, !1
   25    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/NsjJR
function name:  strcmp
number of ops:  6
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'strcmp'
          2        SEND_VAR                                                 !0
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
          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/NsjJR
function name:  strcmp
number of ops:  6
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'strcmp'
          2        SEND_VAR                                                 !0
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
          5      > RETURN                                                   null

End of function strcmp

End of class Om.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.32 ms | 1473 KiB | 26 Q