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('is_subclass_of [object]', function($instance) { is_subclass_of($instance, I::class); }); $results[$key] = $value; [$key, $value] = compute('is_subclass_of [class]', function($instance) { is_subclass_of(A::class, I::class); }); $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 = 102, Position 2 = 129
Branch analysis from position: 102
2 jumps found. (Code = 78) Position 1 = 103, Position 2 = 129
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 102
Branch analysis from position: 102
Branch analysis from position: 129
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 129
filename:       /in/FY4re
function name:  (null)
number of ops:  131
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                                  '%00%7Bclosure%7D%2Fin%2FFY4re%3A7%241'
    9     5        SEND_VAL_EX                                              ~10
          6        DO_FCALL                                      0  $11     
          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
   11    14        INIT_FCALL_BY_NAME                                       'compute'
         15        SEND_VAL_EX                                              'is_subclass_of+%5Bobject%5D'
         16        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FFY4re%3A11%242'
   13    17        SEND_VAL_EX                                              ~17
         18        DO_FCALL                                      0  $18     
         19        FETCH_LIST_R                                     $19     $18, 0
   11    20        ASSIGN                                                   !1, $19
         21        FETCH_LIST_R                                     $21     $18, 1
         22        ASSIGN                                                   !2, $21
         23        FREE                                                     $18
   14    24        ASSIGN_DIM                                               !0, !1
         25        OP_DATA                                                  !2
   15    26        INIT_FCALL_BY_NAME                                       'compute'
         27        SEND_VAL_EX                                              'is_subclass_of+%5Bclass%5D'
         28        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FFY4re%3A15%243'
   17    29        SEND_VAL_EX                                              ~24
         30        DO_FCALL                                      0  $25     
         31        FETCH_LIST_R                                     $26     $25, 0
   15    32        ASSIGN                                                   !1, $26
         33        FETCH_LIST_R                                     $28     $25, 1
         34        ASSIGN                                                   !2, $28
         35        FREE                                                     $25
   18    36        ASSIGN_DIM                                               !0, !1
         37        OP_DATA                                                  !2
   19    38        INIT_FCALL_BY_NAME                                       'compute'
         39        SEND_VAL_EX                                              'class_implements+%5Bobject%5D'
         40        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FFY4re%3A19%244'
   21    41        SEND_VAL_EX                                              ~31
         42        DO_FCALL                                      0  $32     
         43        FETCH_LIST_R                                     $33     $32, 0
   19    44        ASSIGN                                                   !1, $33
         45        FETCH_LIST_R                                     $35     $32, 1
         46        ASSIGN                                                   !2, $35
         47        FREE                                                     $32
   22    48        ASSIGN_DIM                                               !0, !1
         49        OP_DATA                                                  !2
   24    50        INIT_FCALL_BY_NAME                                       'compute'
         51        SEND_VAL_EX                                              'is_a+%5Bobject%5D'
         52        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FFY4re%3A24%245'
   26    53        SEND_VAL_EX                                              ~38
         54        DO_FCALL                                      0  $39     
         55        FETCH_LIST_R                                     $40     $39, 0
   24    56        ASSIGN                                                   !1, $40
         57        FETCH_LIST_R                                     $42     $39, 1
         58        ASSIGN                                                   !2, $42
         59        FREE                                                     $39
   27    60        ASSIGN_DIM                                               !0, !1
         61        OP_DATA                                                  !2
   29    62        INIT_FCALL_BY_NAME                                       'compute'
         63        SEND_VAL_EX                                              'is_a+%5Bclass%5D'
         64        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FFY4re%3A29%246'
   31    65        SEND_VAL_EX                                              ~45
         66        DO_FCALL                                      0  $46     
         67        FETCH_LIST_R                                     $47     $46, 0
   29    68        ASSIGN                                                   !1, $47
         69        FETCH_LIST_R                                     $49     $46, 1
         70        ASSIGN                                                   !2, $49
         71        FREE                                                     $46
   32    72        ASSIGN_DIM                                               !0, !1
         73        OP_DATA                                                  !2
   34    74        INIT_FCALL_BY_NAME                                       'compute'
         75        SEND_VAL_EX                                              'reflection+%5Bclass%5D'
         76        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FFY4re%3A34%247'
   36    77        SEND_VAL_EX                                              ~52
         78        DO_FCALL                                      0  $53     
         79        FETCH_LIST_R                                     $54     $53, 0
   34    80        ASSIGN                                                   !1, $54
         81        FETCH_LIST_R                                     $56     $53, 1
         82        ASSIGN                                                   !2, $56
         83        FREE                                                     $53
   37    84        ASSIGN_DIM                                               !0, !1
         85        OP_DATA                                                  !2
   52    86        INIT_FCALL                                               'asort'
         87        SEND_REF                                                 !0
         88        DO_ICALL                                                 
   53    89        INIT_FCALL                                               'min'
         90        SEND_VAR                                                 !0
         91        DO_ICALL                                         $60     
         92        ASSIGN                                                   !3, $60
   54    93        INIT_FCALL                                               'array_map'
         94        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FFY4re%3A54%248'
         95        BIND_LEXICAL                                             ~62, !3
   59    96        SEND_VAL                                                 ~62
         97        SEND_VAR                                                 !0
         98        DO_ICALL                                         $63     
   54    99        ASSIGN                                                   !0, $63
   61   100        ASSIGN                                                   !4, 0
   62   101      > FE_RESET_R                                       $66     !0, ->129
        102    > > FE_FETCH_R                                       ~67     $66, !5, ->129
        103    >   ASSIGN                                                   !6, ~67
   63   104        QM_ASSIGN                                        ~69     !5
        105        FETCH_LIST_R                                     $70     ~69, 0
        106        ASSIGN                                                   !7, $70
        107        FETCH_LIST_R                                     $72     ~69, 1
        108        ASSIGN                                                   !4, $72
        109        FREE                                                     ~69
   64   110        SUB                                              ~74     !4, 1
        111        MUL                                              ~75     ~74, 100
        112        ASSIGN                                                   !8, ~75
   65   113        INIT_FCALL                                               'sprintf'
   66   114        SEND_VAL                                                 '%2525s+took+%256.2f+ms+%7C+%2B%253.0f%25%25+%7C+%25s'
   67   115        SEND_VAR                                                 !6
   68   116        SEND_VAR                                                 !7
   69   117        SEND_VAR                                                 !8
   70   118        INIT_FCALL                                               'str_pad'
        119        SEND_VAL                                                 ''
        120        MUL                                              ~77     !4, 10
        121        SEND_VAL                                                 ~77
        122        SEND_VAL                                                 '.'
        123        DO_ICALL                                         $78     
        124        SEND_VAR                                                 $78
        125        DO_ICALL                                         $79     
   71   126        CONCAT                                           ~80     $79, '%0A'
        127        ECHO                                                     ~80
   62   128      > JMP                                                      ->102
        129    >   FE_FREE                                                  $66
   72   130      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FFY4re%3A7%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FY4re
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 function %00%7Bclosure%7D%2Fin%2FFY4re%3A7%241

Function %00%7Bclosure%7D%2Fin%2FFY4re%3A11%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FY4re
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'is_subclass_of'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'I'
          4        DO_ICALL                                                 
   13     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FFY4re%3A11%242

Function %00%7Bclosure%7D%2Fin%2FFY4re%3A15%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FY4re
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        INIT_FCALL                                               'is_subclass_of'
          2        SEND_VAL                                                 'A'
          3        SEND_VAL                                                 'I'
          4        DO_ICALL                                                 
   17     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FFY4re%3A15%243

Function %00%7Bclosure%7D%2Fin%2FFY4re%3A19%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FY4re
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     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                                                 
   21     8      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FFY4re%3A19%244

Function %00%7Bclosure%7D%2Fin%2FFY4re%3A24%245:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FY4re
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'is_a'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'I'
          4        DO_ICALL                                                 
   26     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FFY4re%3A24%245

Function %00%7Bclosure%7D%2Fin%2FFY4re%3A29%246:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FY4re
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_FCALL                                               'is_a'
          2        SEND_VAL                                                 'A'
          3        SEND_VAL                                                 'I'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                                 
   31     6      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FFY4re%3A29%246

Function %00%7Bclosure%7D%2Fin%2FFY4re%3A34%247:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FY4re
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     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          
   36     7      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FFY4re%3A34%247

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/FY4re
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
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        NEW                                              $6      'A'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $6
   42     5        INIT_FCALL                                               'microtime'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !3, $9
   43     9        ASSIGN                                                   !4, 100000
         10      > JMP                                                      ->15
   44    11    >   INIT_DYNAMIC_CALL                                        !1
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0          
   43    14        PRE_DEC                                                  !4
         15    > > JMPNZ                                                    !4, ->11
   47    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
   49    22        INIT_ARRAY                                       ~18     !0
         23        ADD_ARRAY_ELEMENT                                ~18     !5
         24      > RETURN                                                   ~18
   50    25*     > RETURN                                                   null

End of function compute

Function %00%7Bclosure%7D%2Fin%2FFY4re%3A54%248:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FY4re
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $result, !1 = $best
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   56     2        INIT_ARRAY                                       ~2      !0
   57     3        DIV                                              ~3      !0, !1
          4        ADD_ARRAY_ELEMENT                                ~2      ~3
          5      > RETURN                                                   ~2
   59     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FFY4re%3A54%248

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
186.87 ms | 1421 KiB | 33 Q