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

End of function benchmarkmemory

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

End of function %00functionwithnoname%2Fin%2FV5f2a%3A10%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.3 ms | 1407 KiB | 27 Q