3v4l.org

run code in 300+ PHP versions simultaneously
<?php version_compare(PHP_VERSION, '7.1', '>=') || die; class MyClass { public static function callStatic($arg, $i) { return sprintf("%s %d\n", $arg, $i); } public function callable($arg, $i) { return sprintf("%s %d\n", $arg, $i); } public static function getCallable() { return [new static(), 'callable']; } public static function getClosure() { return Closure::fromCallable([new static(), 'callable']); } } function callFunc($arg, $i) { return sprintf("%s %d\n", $arg, $i); } $nTests = 100000; $result = 0; foreach([ 'callable' => MyClass::getCallable(), 'closure ' => MyClass::getClosure(), 'callstat' => ['MyClass', 'callStatic'], 'csclosed' => Closure::fromCallable(['MyClass', 'callStatic']), 'function' => 'callFunc', 'fnclosed' => Closure::fromCallable('callFunc'), ] as $name => $function) { ob_start(); $_start = microtime(true); for($i = 0; $i < $nTests; $i++) { $function('callable', $i); } $_end = microtime(true); ob_end_clean(); $_runtime = $_end - $_start; printf("%s in %.4f sec, %5.1f\n", $name, $_runtime, ($result & 1) * 100 * ($_runtime / ($_old ?? $_runtime))); $_old = $_runtime; $result++; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 67
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 67
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 37
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 37
Branch analysis from position: 44
Branch analysis from position: 37
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
filename:       /in/V4uTI
function name:  (null)
number of ops:  69
compiled vars:  !0 = $nTests, !1 = $result, !2 = $function, !3 = $name, !4 = $_start, !5 = $i, !6 = $_end, !7 = $_runtime, !8 = $_old
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'version_compare'
          1        SEND_VAL                                                 '8.0.0'
          2        SEND_VAL                                                 '7.1'
          3        SEND_VAL                                                 '%3E%3D'
          4        DO_ICALL                                         $9      
          5      > JMPNZ_EX                                         ~10     $9, ->8
          6    > > EXIT                                                     
          7*       BOOL                                             ~10     <true>
   33     8    >   ASSIGN                                                   !0, 100000
   34     9        ASSIGN                                                   !1, 0
   36    10        INIT_STATIC_METHOD_CALL                                  'MyClass', 'getCallable'
         11        DO_FCALL                                      0  $13     
         12        INIT_ARRAY                                       ~14     $13, 'callable'
   37    13        INIT_STATIC_METHOD_CALL                                  'MyClass', 'getClosure'
         14        DO_FCALL                                      0  $15     
         15        ADD_ARRAY_ELEMENT                                ~14     $15, 'closure+'
   36    16        ADD_ARRAY_ELEMENT                                ~14     <array>, 'callstat'
   39    17        INIT_STATIC_METHOD_CALL                                  'Closure', 'fromCallable'
         18        SEND_VAL                                                 <array>
         19        DO_FCALL                                      0  $16     
         20        ADD_ARRAY_ELEMENT                                ~14     $16, 'csclosed'
   40    21        ADD_ARRAY_ELEMENT                                ~14     'callFunc', 'function'
   41    22        INIT_STATIC_METHOD_CALL                                  'Closure', 'fromCallable'
         23        SEND_VAL                                                 'callFunc'
         24        DO_FCALL                                      0  $17     
         25        ADD_ARRAY_ELEMENT                                ~14     $17, 'fnclosed'
         26      > FE_RESET_R                                       $18     ~14, ->67
         27    > > FE_FETCH_R                                       ~19     $18, !2, ->67
   42    28    >   ASSIGN                                                   !3, ~19
   44    29        INIT_FCALL                                               'ob_start'
         30        DO_ICALL                                                 
   45    31        INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $22     
         34        ASSIGN                                                   !4, $22
   46    35        ASSIGN                                                   !5, 0
         36      > JMP                                                      ->42
   48    37    >   INIT_DYNAMIC_CALL                                        !2
         38        SEND_VAL_EX                                              'callable'
         39        SEND_VAR_EX                                              !5
         40        DO_FCALL                                      0          
   46    41        PRE_INC                                                  !5
         42    >   IS_SMALLER                                               !5, !0
         43      > JMPNZ                                                    ~27, ->37
   50    44    >   INIT_FCALL                                               'microtime'
         45        SEND_VAL                                                 <true>
         46        DO_ICALL                                         $28     
         47        ASSIGN                                                   !6, $28
   51    48        INIT_FCALL                                               'ob_end_clean'
         49        DO_ICALL                                                 
   53    50        SUB                                              ~31     !6, !4
         51        ASSIGN                                                   !7, ~31
   54    52        INIT_FCALL                                               'printf'
         53        SEND_VAL                                                 '%25s+in+%25.4f+sec%2C+%255.1f%0A'
         54        SEND_VAR                                                 !3
         55        SEND_VAR                                                 !7
         56        BW_AND                                           ~33     !1, 1
         57        MUL                                              ~34     ~33, 100
         58        COALESCE                                         ~35     !8
         59        QM_ASSIGN                                        ~35     !7
         60        DIV                                              ~36     !7, ~35
         61        MUL                                              ~37     ~34, ~36
         62        SEND_VAL                                                 ~37
         63        DO_ICALL                                                 
   55    64        ASSIGN                                                   !8, !7
   56    65        PRE_INC                                                  !1
   36    66      > JMP                                                      ->27
         67    >   FE_FREE                                                  $18
   57    68      > RETURN                                                   1

Function callfunc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V4uTI
function name:  callFunc
number of ops:  9
compiled vars:  !0 = $arg, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   30     2        INIT_FCALL                                               'sprintf'
          3        SEND_VAL                                                 '%25s+%25d%0A'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   31     8*     > RETURN                                                   null

End of function callfunc

Class MyClass:
Function callstatic:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V4uTI
function name:  callStatic
number of ops:  9
compiled vars:  !0 = $arg, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        INIT_FCALL                                               'sprintf'
          3        SEND_VAL                                                 '%25s+%25d%0A'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   10     8*     > RETURN                                                   null

End of function callstatic

Function callable:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V4uTI
function name:  callable
number of ops:  9
compiled vars:  !0 = $arg, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_FCALL                                               'sprintf'
          3        SEND_VAL                                                 '%25s+%25d%0A'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   15     8*     > RETURN                                                   null

End of function callable

Function getcallable:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V4uTI
function name:  getCallable
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   NEW                          static              $0      
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~2      $0
          3        ADD_ARRAY_ELEMENT                                ~2      'callable'
          4      > RETURN                                                   ~2
   20     5*     > RETURN                                                   null

End of function getcallable

Function getclosure:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V4uTI
function name:  getClosure
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_STATIC_METHOD_CALL                                  'Closure', 'fromCallable'
          1        NEW                          static              $0      
          2        DO_FCALL                                      0          
          3        INIT_ARRAY                                       ~2      $0
          4        ADD_ARRAY_ELEMENT                                ~2      'callable'
          5        SEND_VAL                                                 ~2
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
   25     8*     > RETURN                                                   null

End of function getclosure

End of class MyClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.17 ms | 1408 KiB | 25 Q