3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmarkMemory(callable $function, $args=null) { declare(ticks=1); if(!class_exists('classWithNoName')) { class classWithNoName { public static $memory, $max; } function functionWithNoName() { classWithNoName::$memory = memory_get_usage() - classWithNoName::$memory; classWithNoName::$max = classWithNoName::$memory>classWithNoName::$max? classWithNoName::$memory: classWithNoName::$max; classWithNoName::$memory = memory_get_usage(); } classWithNoName::$memory = memory_get_usage(); classWithNoName::$max = 0; } if (function_exists('register_tick_function')): register_tick_function('functionWithNoName'); $result = is_array($args)? call_user_func_array($function, $args): call_user_func_array($function); unregister_tick_function('functionWithNoName'); endif; $memory = classWithNoName::$max; classWithNoName::$max = 0; return [ 'memory' => $memory ]; } var_dump(benchmarkMemory('str_repeat', ['test',1E4]));//40068 var_dump(benchmarkMemory('str_repeat', ['test',1E3]));//4040
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6GEoj
function name:  (null)
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     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                                                    
   38     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 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 47
Branch analysis from position: 25
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: 47
Branch analysis from position: 21
filename:       /in/6GEoj
function name:  benchmarkMemory
number of ops:  57
compiled vars:  !0 = $function, !1 = $args, !2 = $result, !3 = $memory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    4     2        TICKS                                                    
    5     3        INIT_FCALL                                               'class_exists'
          4        SEND_VAL                                                 'classWithNoName'
          5        DO_ICALL                                         $4      
          6        BOOL_NOT                                         ~5      $4
          7      > JMPZ                                                     ~5, ->21
    9     8    >   TICKS                                                    
    7     9        DECLARE_CLASS                                            'classwithnoname'
         10        TICKS                                                    
   12    11        DECLARE_FUNCTION                                         'functionwithnoname'
   19    12        TICKS                                                    
   20    13        INIT_FCALL                                               'memory_get_usage'
         14        DO_ICALL                                         $7      
         15        ASSIGN_STATIC_PROP                                       'memory', 'classWithNoName'
         16        OP_DATA                                                  $7
         17        TICKS                                                    
   21    18        ASSIGN_STATIC_PROP                                       'max', 'classWithNoName'
         19        OP_DATA                                                  0
         20        TICKS                                                    
   23    21    >   INIT_FCALL                                               'function_exists'
         22        SEND_VAL                                                 'register_tick_function'
         23        DO_ICALL                                         $9      
         24      > JMPZ                                                     $9, ->47
   24    25    >   INIT_FCALL                                               'register_tick_function'
         26        SEND_VAL                                                 'functionWithNoName'
         27        DO_ICALL                                                 
         28        TICKS                                                    
   25    29        TYPE_CHECK                                  128          !1
         30      > JMPZ                                                     ~11, ->37
   26    31    >   INIT_USER_CALL                                0          'call_user_func_array', !0
         32        SEND_ARRAY                                               !1
         33        CHECK_UNDEF_ARGS                                         
         34        DO_FCALL                                      0  $12     
         35        QM_ASSIGN                                        ~13     $12
         36      > JMP                                                      ->41
   27    37    >   INIT_FCALL                                               'call_user_func_array'
         38        SEND_VAR                                                 !0
         39        DO_ICALL                                         $14     
         40        QM_ASSIGN                                        ~13     $14
   25    41    >   ASSIGN                                                   !2, ~13
         42        TICKS                                                    
   28    43        INIT_FCALL                                               'unregister_tick_function'
         44        SEND_VAL                                                 'functionWithNoName'
         45        DO_ICALL                                                 
         46        TICKS                                                    
   30    47    >   FETCH_STATIC_PROP_R          unknown             ~17     'max'
         48        ASSIGN                                                   !3, ~17
         49        TICKS                                                    
   31    50        ASSIGN_STATIC_PROP                                       'max', 'classWithNoName'
         51        OP_DATA                                                  0
         52        TICKS                                                    
   33    53        INIT_ARRAY                                       ~20     !3, 'memory'
         54      > RETURN                                                   ~20
         55*       TICKS                                                    
   35    56*     > RETURN                                                   null

End of function benchmarkmemory

Function %00functionwithnoname%2Fin%2F6GEoj%3A12%241:
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/6GEoj
function name:  functionWithNoName
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     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', 'classWithNoName'
          5        OP_DATA                                                  ~3
          6        TICKS                                                    
   15     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
   16    11    >   FETCH_STATIC_PROP_R          unknown             ~8      'memory'
         12        QM_ASSIGN                                        ~9      ~8
         13      > JMP                                                      ->16
   17    14    >   FETCH_STATIC_PROP_R          unknown             ~10     'max'
         15        QM_ASSIGN                                        ~9      ~10
   15    16    >   ASSIGN_STATIC_PROP                                       'max', 'classWithNoName'
   17    17        OP_DATA                                                  ~9
         18        TICKS                                                    
   18    19        INIT_FCALL                                               'memory_get_usage'
         20        DO_ICALL                                         $12     
         21        ASSIGN_STATIC_PROP                                       'memory', 'classWithNoName'
         22        OP_DATA                                                  $12
         23        TICKS                                                    
   19    24      > RETURN                                                   null

End of function %00functionwithnoname%2Fin%2F6GEoj%3A12%241

Class classWithNoName: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.01 ms | 1407 KiB | 29 Q