3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmarkMemory(callable $function, $args=null) { declare(ticks=1); global $_memory, $_max; $_memory = memory_get_usage(); $_max = 0; if(!function_exists('functionWithNoName')) { function functionWithNoName() { global $_memory, $_max; $_memory = memory_get_usage() - $_memory; $_max = $_memory>$_max?$_memory:$_max; $_memory = memory_get_usage(); } } register_tick_function('functionWithNoName'); $result = is_array($args)? call_user_func_array($function, $args): call_user_func_array($function); unregister_tick_function('functionWithNoName'); 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/OPrPa
function name:  (null)
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     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                                                    
   30     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 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/OPrPa
function name:  benchmarkMemory
number of ops:  46
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        BIND_GLOBAL                                              !2, '_memory'
          4        TICKS                                                    
          5        BIND_GLOBAL                                              !3, '_max'
          6        TICKS                                                    
    7     7        INIT_FCALL                                               'memory_get_usage'
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !2, $5
         10        TICKS                                                    
    8    11        ASSIGN                                                   !3, 0
         12        TICKS                                                    
    9    13        INIT_FCALL                                               'function_exists'
         14        SEND_VAL                                                 'functionWithNoName'
         15        DO_ICALL                                         $8      
         16        BOOL_NOT                                         ~9      $8
         17      > JMPZ                                                     ~9, ->20
   11    18    >   DECLARE_FUNCTION                                         'functionwithnoname'
   17    19        TICKS                                                    
   19    20    >   INIT_FCALL                                               'register_tick_function'
         21        SEND_VAL                                                 'functionWithNoName'
         22        DO_ICALL                                                 
         23        TICKS                                                    
   20    24        TYPE_CHECK                                  128          !1
         25      > JMPZ                                                     ~11, ->32
   21    26    >   INIT_USER_CALL                                0          'call_user_func_array', !0
         27        SEND_ARRAY                                               !1
         28        CHECK_UNDEF_ARGS                                         
         29        DO_FCALL                                      0  $12     
         30        QM_ASSIGN                                        ~13     $12
         31      > JMP                                                      ->36
   22    32    >   INIT_FCALL                                               'call_user_func_array'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                         $14     
         35        QM_ASSIGN                                        ~13     $14
   20    36    >   ASSIGN                                                   !4, ~13
         37        TICKS                                                    
   23    38        INIT_FCALL                                               'unregister_tick_function'
         39        SEND_VAL                                                 'functionWithNoName'
         40        DO_ICALL                                                 
         41        TICKS                                                    
   25    42        INIT_ARRAY                                       ~17     !3, 'memory'
         43      > RETURN                                                   ~17
         44*       TICKS                                                    
   27    45*     > RETURN                                                   null

End of function benchmarkmemory

Function %00functionwithnoname%2Fin%2FOPrPa%3A11%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OPrPa
function name:  functionWithNoName
number of ops:  21
compiled vars:  !0 = $_memory, !1 = $_max
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   BIND_GLOBAL                                              !0, '_memory'
          1        TICKS                                                    
          2        BIND_GLOBAL                                              !1, '_max'
          3        TICKS                                                    
   14     4        INIT_FCALL                                               'memory_get_usage'
          5        DO_ICALL                                         $2      
          6        SUB                                              ~3      $2, !0
          7        ASSIGN                                                   !0, ~3
          8        TICKS                                                    
   15     9        IS_SMALLER                                               !1, !0
         10      > JMPZ                                                     ~5, ->13
         11    >   QM_ASSIGN                                        ~6      !0
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~6      !1
         14    >   ASSIGN                                                   !1, ~6
         15        TICKS                                                    
   16    16        INIT_FCALL                                               'memory_get_usage'
         17        DO_ICALL                                         $8      
         18        ASSIGN                                                   !0, $8
         19        TICKS                                                    
   17    20      > RETURN                                                   null

End of function %00functionwithnoname%2Fin%2FOPrPa%3A11%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.21 ms | 1407 KiB | 27 Q