3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmarkMemory(callable $function, $args=null) { declare(ticks=1); $memory = memory_get_usage(); $max = 0; if(!class_exists('classWithNoName')) { class classWithNoName { public static $memory, $max; public function __invoke() { self::$memory = memory_get_usage() - self::$memory; self::$max = self::$memory>self::$max?self::$memory:self::$max; self::$memory = memory_get_usage(); } public function __toString() { return __CLASS__; } } classWithNoName::$memory = memory_get_usage(); classWithNoName::$max = 0; } register_tick_function('classWithNoName'); $result = is_array($args)? call_user_func_array($function, $args): call_user_func_array($function); unregister_tick_function('classWithNoName'); return [ 'memory' => $max ]; } var_dump(benchmarkMemory('str_repeat', ['test',1E4]));//0 var_dump(benchmarkMemory('str_repeat', ['test',1E3]));//0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TelNe
function name:  (null)
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'benchmarkmemory'
          2        SEND_VAL                                                 'str_repeat'
          3        SEND_VAL                                                 <array>
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7        TICKS                                                    
   39     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'benchmarkmemory'
         10        SEND_VAL                                                 'str_repeat'
         11        SEND_VAL                                                 <array>
         12        DO_FCALL                                      0  $2      
         13        SEND_VAR                                                 $2
         14        DO_ICALL                                                 
         15        TICKS                                                    
         16      > RETURN                                                   1

Function benchmarkmemory:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 37
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/TelNe
function name:  benchmarkMemory
number of ops:  51
compiled vars:  !0 = $function, !1 = $args, !2 = $memory, !3 = $max, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    5     2        TICKS                                                    
    6     3        INIT_FCALL                                               'memory_get_usage'
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !2, $5
          6        TICKS                                                    
    7     7        ASSIGN                                                   !3, 0
          8        TICKS                                                    
    8     9        INIT_FCALL                                               'class_exists'
         10        SEND_VAL                                                 'classWithNoName'
         11        DO_ICALL                                         $8      
         12        BOOL_NOT                                         ~9      $8
         13      > JMPZ                                                     ~9, ->25
   12    14    >   TICKS                                                    
   10    15        DECLARE_CLASS                                            'classwithnoname'
         16        TICKS                                                    
   25    17        INIT_FCALL                                               'memory_get_usage'
         18        DO_ICALL                                         $11     
         19        ASSIGN_STATIC_PROP                                       'memory', 'classWithNoName'
         20        OP_DATA                                                  $11
         21        TICKS                                                    
   26    22        ASSIGN_STATIC_PROP                                       'max', 'classWithNoName'
         23        OP_DATA                                                  0
         24        TICKS                                                    
   28    25    >   INIT_FCALL                                               'register_tick_function'
         26        SEND_VAL                                                 'classWithNoName'
         27        DO_ICALL                                                 
         28        TICKS                                                    
   29    29        TYPE_CHECK                                  128          !1
         30      > JMPZ                                                     ~14, ->37
   30    31    >   INIT_USER_CALL                                0          'call_user_func_array', !0
         32        SEND_ARRAY                                               !1
         33        CHECK_UNDEF_ARGS                                         
         34        DO_FCALL                                      0  $15     
         35        QM_ASSIGN                                        ~16     $15
         36      > JMP                                                      ->41
   31    37    >   INIT_FCALL                                               'call_user_func_array'
         38        SEND_VAR                                                 !0
         39        DO_ICALL                                         $17     
         40        QM_ASSIGN                                        ~16     $17
   29    41    >   ASSIGN                                                   !4, ~16
         42        TICKS                                                    
   32    43        INIT_FCALL                                               'unregister_tick_function'
         44        SEND_VAL                                                 'classWithNoName'
         45        DO_ICALL                                                 
         46        TICKS                                                    
   34    47        INIT_ARRAY                                       ~20     !3, 'memory'
         48      > RETURN                                                   ~20
         49*       TICKS                                                    
   36    50*     > RETURN                                                   null

End of function benchmarkmemory

Class classWithNoName:
Function __invoke:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TelNe
function name:  __invoke
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'memory_get_usage'
          1        DO_ICALL                                         $1      
          2        FETCH_STATIC_PROP_R          unknown             ~2      'memory'
          3        SUB                                              ~3      $1, ~2
          4        ASSIGN_STATIC_PROP                                       'memory'
          5        OP_DATA                                                  ~3
          6        TICKS                                                    
   16     7        FETCH_STATIC_PROP_R          unknown             ~5      'memory'
          8        FETCH_STATIC_PROP_R          unknown             ~6      'max'
          9        IS_SMALLER                                               ~6, ~5
         10      > JMPZ                                                     ~7, ->14
         11    >   FETCH_STATIC_PROP_R          unknown             ~8      'memory'
         12        QM_ASSIGN                                        ~9      ~8
         13      > JMP                                                      ->16
         14    >   FETCH_STATIC_PROP_R          unknown             ~10     'max'
         15        QM_ASSIGN                                        ~9      ~10
         16    >   ASSIGN_STATIC_PROP                                       'max'
         17        OP_DATA                                                  ~9
         18        TICKS                                                    
   17    19        INIT_FCALL                                               'memory_get_usage'
         20        DO_ICALL                                         $12     
         21        ASSIGN_STATIC_PROP                                       'memory'
         22        OP_DATA                                                  $12
         23        TICKS                                                    
   18    24      > RETURN                                                   null

End of function __invoke

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TelNe
function name:  __toString
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E > > RETURN                                                   'classWithNoName'
          1*       TICKS                                                    
   23     2*       VERIFY_RETURN_TYPE                                       
          3*     > RETURN                                                   null

End of function __tostring

End of class classWithNoName.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.53 ms | 1407 KiB | 27 Q