3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Foo\Bar { class Baz {} } namespace { function byReflection($obj) { $r = new ReflectionObject($obj); return $r->getShortName(); } function byString($obj) { $class = get_class($obj); return ltrim(strrchr($class, '\\'), '\\') ?: $class; } function benchmark(callable $func, $param, $message) { echo "Benchmarking $message\n"; $s = microtime(true); for ($i = 0; $i < 10000; $i++) { $func($param); } $e = microtime(true); echo " - Completed in " . ($e - $s) . " seconds\n"; } $a = new StdClass; $b = new Foo\Bar\Baz; benchmark("byReflection", $a, "By Reflection, No Namespace"); benchmark("byReflection", $b, "By Reflection, Namespace"); benchmark("byString", $a, "By String, No Namespace"); benchmark("byString", $b, "By String, Namespace"); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dsmWG
function name:  (null)
number of ops:  27
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   NEW                                              $2      'StdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   30     3        NEW                                              $5      'Foo%5CBar%5CBaz'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   32     6        INIT_FCALL                                               'benchmark'
          7        SEND_VAL                                                 'byReflection'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 'By+Reflection%2C+No+Namespace'
         10        DO_FCALL                                      0          
   33    11        INIT_FCALL                                               'benchmark'
         12        SEND_VAL                                                 'byReflection'
         13        SEND_VAR                                                 !1
         14        SEND_VAL                                                 'By+Reflection%2C+Namespace'
         15        DO_FCALL                                      0          
   35    16        INIT_FCALL                                               'benchmark'
         17        SEND_VAL                                                 'byString'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 'By+String%2C+No+Namespace'
         20        DO_FCALL                                      0          
   36    21        INIT_FCALL                                               'benchmark'
         22        SEND_VAL                                                 'byString'
         23        SEND_VAR                                                 !1
         24        SEND_VAL                                                 'By+String%2C+Namespace'
         25        DO_FCALL                                      0          
   37    26      > RETURN                                                   1

Function byreflection:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dsmWG
function name:  byReflection
number of ops:  9
compiled vars:  !0 = $obj, !1 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        NEW                                              $2      'ReflectionObject'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $2
   11     5        INIT_METHOD_CALL                                         !1, 'getShortName'
          6        DO_FCALL                                      0  $5      
          7      > RETURN                                                   $5
   12     8*     > RETURN                                                   null

End of function byreflection

Function bystring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dsmWG
function name:  byString
number of ops:  15
compiled vars:  !0 = $obj, !1 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        GET_CLASS                                        ~2      !0
          2        ASSIGN                                                   !1, ~2
   16     3        INIT_FCALL                                               'ltrim'
          4        INIT_FCALL                                               'strrchr'
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 '%5C'
          7        DO_ICALL                                         $4      
          8        SEND_VAR                                                 $4
          9        SEND_VAL                                                 '%5C'
         10        DO_ICALL                                         $5      
         11        JMP_SET                                          ~6      $5, ->13
         12        QM_ASSIGN                                        ~6      !1
         13      > RETURN                                                   ~6
   17    14*     > RETURN                                                   null

End of function bystring

Function benchmark:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 13
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 13
Branch analysis from position: 19
Branch analysis from position: 13
filename:       /in/dsmWG
function name:  benchmark
number of ops:  28
compiled vars:  !0 = $func, !1 = $param, !2 = $message, !3 = $s, !4 = $i, !5 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   20     3        ROPE_INIT                                     3  ~7      'Benchmarking+'
          4        ROPE_ADD                                      1  ~7      ~7, !2
          5        ROPE_END                                      2  ~6      ~7, '%0A'
          6        ECHO                                                     ~6
   21     7        INIT_FCALL                                               'microtime'
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !3, $9
   22    11        ASSIGN                                                   !4, 0
         12      > JMP                                                      ->17
   23    13    >   INIT_DYNAMIC_CALL                                        !0
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
   22    16        PRE_INC                                                  !4
         17    >   IS_SMALLER                                               !4, 10000
         18      > JMPNZ                                                    ~14, ->13
   25    19    >   INIT_FCALL                                               'microtime'
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $15     
         22        ASSIGN                                                   !5, $15
   26    23        SUB                                              ~17     !5, !3
         24        CONCAT                                           ~18     '++-+Completed+in+', ~17
         25        CONCAT                                           ~19     ~18, '+seconds%0A'
         26        ECHO                                                     ~19
   27    27      > RETURN                                                   null

End of function benchmark

Class Foo\Bar\Baz: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.79 ms | 1407 KiB | 23 Q