3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface I {} class A implements I{} $results = []; [$key, $value] = compute('instanceof [object]', function($instance) { $instance instanceof I; }); $results[$key] = $value; [$key, $value] = compute('class_implements [object]', function($instance) { in_array(I::class, class_implements(A::class)); }); $results[$key] = $value; [$key, $value] = compute('is_a [object]', function($instance) { is_a($instance, I::class); }); $results[$key] = $value; [$key, $value] = compute('is_a [class]', function($instance) { is_a(A::class, I::class, true); }); $results[$key] = $value; [$key, $value] = compute('reflection [class]', function($instance) { ( new ReflectionClass(A::class))->implementsInterface(I::class); }); $results[$key] = $value; function compute($name, $callback) { $instance = new A; $start = microtime(true); for($i = 1e5; $i; $i--) { $callback($instance); } $elapsedMs = (microtime(true) - $start)*1000; return [$name, $elapsedMs]; } asort($results); $best = min($results); $results = array_map(function($result) use($best) { return [ $result, $result / $best, ]; }, $results); $performance = 0; foreach($results as $name => $result) { [$elapsedMs, $performance] = $result; $extraTimeInPercent = ($performance - 1) * 100; echo sprintf( '%25s took %6.2f ms | +%3.0f%% | %s', $name, $elapsedMs, $extraTimeInPercent, str_pad('', ($performance * 10), '.') ) . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 78, Position 2 = 105
Branch analysis from position: 78
2 jumps found. (Code = 78) Position 1 = 79, Position 2 = 105
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 105
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 105
filename:       /in/8Cog7
function name:  (null)
number of ops:  107
compiled vars:  !0 = $results, !1 = $key, !2 = $value, !3 = $best, !4 = $performance, !5 = $result, !6 = $name, !7 = $elapsedMs, !8 = $extraTimeInPercent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'a'
    5     1        ASSIGN                                                   !0, <array>
    7     2        INIT_FCALL_BY_NAME                                       'compute'
          3        SEND_VAL_EX                                              'instanceof+%5Bobject%5D'
          4        DECLARE_LAMBDA_FUNCTION                          ~10     [0]
    9     5        SEND_VAL_EX                                              ~10
    7     6        DO_FCALL                                      0  $11     
    9     7        FETCH_LIST_R                                     $12     $11, 0
    7     8        ASSIGN                                                   !1, $12
          9        FETCH_LIST_R                                     $14     $11, 1
         10        ASSIGN                                                   !2, $14
         11        FREE                                                     $11
   10    12        ASSIGN_DIM                                               !0, !1
         13        OP_DATA                                                  !2
   12    14        INIT_FCALL_BY_NAME                                       'compute'
         15        SEND_VAL_EX                                              'class_implements+%5Bobject%5D'
         16        DECLARE_LAMBDA_FUNCTION                          ~17     [1]
   14    17        SEND_VAL_EX                                              ~17
   12    18        DO_FCALL                                      0  $18     
   14    19        FETCH_LIST_R                                     $19     $18, 0
   12    20        ASSIGN                                                   !1, $19
         21        FETCH_LIST_R                                     $21     $18, 1
         22        ASSIGN                                                   !2, $21
         23        FREE                                                     $18
   15    24        ASSIGN_DIM                                               !0, !1
         25        OP_DATA                                                  !2
   17    26        INIT_FCALL_BY_NAME                                       'compute'
         27        SEND_VAL_EX                                              'is_a+%5Bobject%5D'
         28        DECLARE_LAMBDA_FUNCTION                          ~24     [2]
   19    29        SEND_VAL_EX                                              ~24
   17    30        DO_FCALL                                      0  $25     
   19    31        FETCH_LIST_R                                     $26     $25, 0
   17    32        ASSIGN                                                   !1, $26
         33        FETCH_LIST_R                                     $28     $25, 1
         34        ASSIGN                                                   !2, $28
         35        FREE                                                     $25
   20    36        ASSIGN_DIM                                               !0, !1
         37        OP_DATA                                                  !2
   22    38        INIT_FCALL_BY_NAME                                       'compute'
         39        SEND_VAL_EX                                              'is_a+%5Bclass%5D'
         40        DECLARE_LAMBDA_FUNCTION                          ~31     [3]
   24    41        SEND_VAL_EX                                              ~31
   22    42        DO_FCALL                                      0  $32     
   24    43        FETCH_LIST_R                                     $33     $32, 0
   22    44        ASSIGN                                                   !1, $33
         45        FETCH_LIST_R                                     $35     $32, 1
         46        ASSIGN                                                   !2, $35
         47        FREE                                                     $32
   25    48        ASSIGN_DIM                                               !0, !1
         49        OP_DATA                                                  !2
   27    50        INIT_FCALL_BY_NAME                                       'compute'
         51        SEND_VAL_EX                                              'reflection+%5Bclass%5D'
         52        DECLARE_LAMBDA_FUNCTION                          ~38     [4]
   29    53        SEND_VAL_EX                                              ~38
   27    54        DO_FCALL                                      0  $39     
   29    55        FETCH_LIST_R                                     $40     $39, 0
   27    56        ASSIGN                                                   !1, $40
         57        FETCH_LIST_R                                     $42     $39, 1
         58        ASSIGN                                                   !2, $42
         59        FREE                                                     $39
   30    60        ASSIGN_DIM                                               !0, !1
         61        OP_DATA                                                  !2
   45    62        INIT_FCALL                                               'asort'
         63        SEND_REF                                                 !0
         64        DO_ICALL                                                 
   46    65        INIT_FCALL                                               'min'
         66        SEND_VAR                                                 !0
         67        DO_ICALL                                         $46     
         68        ASSIGN                                                   !3, $46
   47    69        INIT_FCALL                                               'array_map'
         70        DECLARE_LAMBDA_FUNCTION                          ~48     [5]
         71        BIND_LEXICAL                                             ~48, !3
   52    72        SEND_VAL                                                 ~48
         73        SEND_VAR                                                 !0
   47    74        DO_ICALL                                         $49     
         75        ASSIGN                                                   !0, $49
   54    76        ASSIGN                                                   !4, 0
   55    77      > FE_RESET_R                                       $52     !0, ->105
         78    > > FE_FETCH_R                                       ~53     $52, !5, ->105
         79    >   ASSIGN                                                   !6, ~53
   56    80        QM_ASSIGN                                        ~55     !5
         81        FETCH_LIST_R                                     $56     ~55, 0
         82        ASSIGN                                                   !7, $56
         83        FETCH_LIST_R                                     $58     ~55, 1
         84        ASSIGN                                                   !4, $58
         85        FREE                                                     ~55
   57    86        SUB                                              ~60     !4, 1
         87        MUL                                              ~61     ~60, 100
         88        ASSIGN                                                   !8, ~61
   58    89        INIT_FCALL                                               'sprintf'
   59    90        SEND_VAL                                                 '%2525s+took+%256.2f+ms+%7C+%2B%253.0f%25%25+%7C+%25s'
   60    91        SEND_VAR                                                 !6
   61    92        SEND_VAR                                                 !7
   62    93        SEND_VAR                                                 !8
   63    94        INIT_FCALL                                               'str_pad'
         95        SEND_VAL                                                 ''
         96        MUL                                              ~63     !4, 10
         97        SEND_VAL                                                 ~63
         98        SEND_VAL                                                 '.'
         99        DO_ICALL                                         $64     
        100        SEND_VAR                                                 $64
   58   101        DO_ICALL                                         $65     
   64   102        CONCAT                                           ~66     $65, '%0A'
        103        ECHO                                                     ~66
   55   104      > JMP                                                      ->78
        105    >   FE_FREE                                                  $52
   65   106      > 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/8Cog7
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INSTANCEOF                                       ~1      !0, 'I'
          2        FREE                                                     ~1
    9     3      > 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/8Cog7
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'in_array'
          2        SEND_VAL                                                 'I'
          3        INIT_FCALL                                               'class_implements'
          4        SEND_VAL                                                 'A'
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
          7        DO_ICALL                                                 
   14     8      > 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/8Cog7
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        INIT_FCALL                                               'is_a'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'I'
          4        DO_ICALL                                                 
   19     5      > 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/8Cog7
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        INIT_FCALL                                               'is_a'
          2        SEND_VAL                                                 'A'
          3        SEND_VAL                                                 'I'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                                 
   24     6      > RETURN                                                   null

End of Dynamic Function 3

Dynamic Function 4
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Cog7
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        NEW                                              $1      'ReflectionClass'
          2        SEND_VAL_EX                                              'A'
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $1, 'implementsInterface'
          5        SEND_VAL_EX                                              'I'
          6        DO_FCALL                                      0          
   29     7      > RETURN                                                   null

End of Dynamic Function 4

Dynamic Function 5
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Cog7
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $result, !1 = $best
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   49     2        INIT_ARRAY                                       ~2      !0
   50     3        DIV                                              ~3      !0, !1
          4        ADD_ARRAY_ELEMENT                                ~2      ~3
          5      > RETURN                                                   ~2
   52     6*     > RETURN                                                   null

End of Dynamic Function 5

Function compute:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 11
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 11
Branch analysis from position: 16
Branch analysis from position: 11
filename:       /in/8Cog7
function name:  compute
number of ops:  26
compiled vars:  !0 = $name, !1 = $callback, !2 = $instance, !3 = $start, !4 = $i, !5 = $elapsedMs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        NEW                                              $6      'A'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $6
   35     5        INIT_FCALL                                               'microtime'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !3, $9
   36     9        ASSIGN                                                   !4, 100000
         10      > JMP                                                      ->15
   37    11    >   INIT_DYNAMIC_CALL                                        !1
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0          
   36    14        PRE_DEC                                                  !4
         15    > > JMPNZ                                                    !4, ->11
   40    16    >   INIT_FCALL                                               'microtime'
         17        SEND_VAL                                                 <true>
         18        DO_ICALL                                         $14     
         19        SUB                                              ~15     $14, !3
         20        MUL                                              ~16     ~15, 1000
         21        ASSIGN                                                   !5, ~16
   42    22        INIT_ARRAY                                       ~18     !0
         23        ADD_ARRAY_ELEMENT                                ~18     !5
         24      > RETURN                                                   ~18
   43    25*     > RETURN                                                   null

End of function compute

Class I: [no user functions]
Class A: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.37 ms | 1485 KiB | 22 Q