3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Example { public function __construct() { } public static function create() { return new self(); } public function doStuff() { } public static function doStaticStuff() { } } $named = function () { Example::create()->doStuff(); }; $static = function () { Example::doStaticStuff(); }; $test = function ($count) use ($named, $static) { $loop = function ($count, $callable) { $time_start = microtime(true) * 1000; $memory_start = memory_get_usage(true); for ($i = 0; $i < $count; $i++) { $callable(); } $time_end = microtime(true) * 1000; $memory_end = memory_get_usage(true); return [ $time_end - $time_start, $memory_end - $memory_start, ]; }; $static_delta = $loop($count, $static); $named_delta = $loop($count, $named); echo 'After ' . number_format($count) . " calls:\n"; echo 'Difference in milliseconds: '; var_dump($named_delta[0] - $static_delta[0]); echo 'Difference in memory usage: '; var_dump($named_delta[1] - $static_delta[1]); echo "-----------------------------\n"; }; $test(1); $test(10); $test(100); $test(1000); $test(10000); $test(100000);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/57rc3
function name:  (null)
number of ops:  27
compiled vars:  !0 = $named, !1 = $static, !2 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F57rc3%3A24%240'
          1        ASSIGN                                                   !0, ~3
   28     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F57rc3%3A28%241'
          3        ASSIGN                                                   !1, ~5
   32     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F57rc3%3A32%242'
          5        BIND_LEXICAL                                             ~7, !0
          6        BIND_LEXICAL                                             ~7, !1
          7        ASSIGN                                                   !2, ~7
   61     8        INIT_DYNAMIC_CALL                                        !2
          9        SEND_VAL_EX                                              1
         10        DO_FCALL                                      0          
   62    11        INIT_DYNAMIC_CALL                                        !2
         12        SEND_VAL_EX                                              10
         13        DO_FCALL                                      0          
   63    14        INIT_DYNAMIC_CALL                                        !2
         15        SEND_VAL_EX                                              100
         16        DO_FCALL                                      0          
   64    17        INIT_DYNAMIC_CALL                                        !2
         18        SEND_VAL_EX                                              1000
         19        DO_FCALL                                      0          
   65    20        INIT_DYNAMIC_CALL                                        !2
         21        SEND_VAL_EX                                              10000
         22        DO_FCALL                                      0          
   66    23        INIT_DYNAMIC_CALL                                        !2
         24        SEND_VAL_EX                                              100000
         25        DO_FCALL                                      0          
         26      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F57rc3%3A24%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/57rc3
function name:  {closure}
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_STATIC_METHOD_CALL                                  'Example', 'create'
          1        DO_FCALL                                      0  $0      
          2        INIT_METHOD_CALL                                         $0, 'doStuff'
          3        DO_FCALL                                      0          
   26     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F57rc3%3A24%240

Function %00%7Bclosure%7D%2Fin%2F57rc3%3A28%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/57rc3
function name:  {closure}
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_STATIC_METHOD_CALL                                  'Example', 'doStaticStuff'
          1        DO_FCALL                                      0          
   30     2      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F57rc3%3A28%241

Function %00%7Bclosure%7D%2Fin%2F57rc3%3A32%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/57rc3
function name:  {closure}
number of ops:  37
compiled vars:  !0 = $count, !1 = $named, !2 = $static, !3 = $loop, !4 = $static_delta, !5 = $named_delta
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   33     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F57rc3%3A33%243'
          4        ASSIGN                                                   !3, ~6
   50     5        INIT_DYNAMIC_CALL                                        !3
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !4, $8
   51    10        INIT_DYNAMIC_CALL                                        !3
         11        SEND_VAR_EX                                              !0
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0  $10     
         14        ASSIGN                                                   !5, $10
   53    15        INIT_FCALL                                               'number_format'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $12     
         18        CONCAT                                           ~13     'After+', $12
         19        CONCAT                                           ~14     ~13, '+calls%3A%0A'
         20        ECHO                                                     ~14
   54    21        ECHO                                                     'Difference+in+milliseconds%3A+'
   55    22        INIT_FCALL                                               'var_dump'
         23        FETCH_DIM_R                                      ~15     !5, 0
         24        FETCH_DIM_R                                      ~16     !4, 0
         25        SUB                                              ~17     ~15, ~16
         26        SEND_VAL                                                 ~17
         27        DO_ICALL                                                 
   56    28        ECHO                                                     'Difference+in+memory+usage%3A+'
   57    29        INIT_FCALL                                               'var_dump'
         30        FETCH_DIM_R                                      ~19     !5, 1
         31        FETCH_DIM_R                                      ~20     !4, 1
         32        SUB                                              ~21     ~19, ~20
         33        SEND_VAL                                                 ~21
         34        DO_ICALL                                                 
   58    35        ECHO                                                     '-----------------------------%0A'
   59    36      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F57rc3%3A32%242

Function %00%7Bclosure%7D%2Fin%2F57rc3%3A33%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 13
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 13
Branch analysis from position: 18
Branch analysis from position: 13
filename:       /in/57rc3
function name:  {closure}
number of ops:  33
compiled vars:  !0 = $count, !1 = $callable, !2 = $time_start, !3 = $memory_start, !4 = $i, !5 = $time_end, !6 = $memory_end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   34     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $7      
          5        MUL                                              ~8      $7, 1000
          6        ASSIGN                                                   !2, ~8
   35     7        INIT_FCALL                                               'memory_get_usage'
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $10     
         10        ASSIGN                                                   !3, $10
   37    11        ASSIGN                                                   !4, 0
         12      > JMP                                                      ->16
   38    13    >   INIT_DYNAMIC_CALL                                        !1
         14        DO_FCALL                                      0          
   37    15        PRE_INC                                                  !4
         16    >   IS_SMALLER                                               !4, !0
         17      > JMPNZ                                                    ~15, ->13
   41    18    >   INIT_FCALL                                               'microtime'
         19        SEND_VAL                                                 <true>
         20        DO_ICALL                                         $16     
         21        MUL                                              ~17     $16, 1000
         22        ASSIGN                                                   !5, ~17
   42    23        INIT_FCALL                                               'memory_get_usage'
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $19     
         26        ASSIGN                                                   !6, $19
   45    27        SUB                                              ~21     !5, !2
         28        INIT_ARRAY                                       ~22     ~21
   46    29        SUB                                              ~23     !6, !3
         30        ADD_ARRAY_ELEMENT                                ~22     ~23
         31      > RETURN                                                   ~22
   48    32*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F57rc3%3A33%243

Class Example:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/57rc3
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E > > RETURN                                                   null

End of function __construct

Function create:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/57rc3
function name:  create
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   NEW                          self                $0      
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   12     3*     > RETURN                                                   null

End of function create

Function dostuff:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/57rc3
function name:  doStuff
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E > > RETURN                                                   null

End of function dostuff

Function dostaticstuff:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/57rc3
function name:  doStaticStuff
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E > > RETURN                                                   null

End of function dostaticstuff

End of class Example.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.55 ms | 1408 KiB | 21 Q