3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Benchmark { private static $max, $memory; public static function memoryTick() { self::$memory = memory_get_usage() - self::$memory; self::$max = self::$memory>self::$max?self::$memory:self::$max; self::$memory = memory_get_usage(); } public static function benchmarkMemory(callable $function, $args=null) { declare(ticks=1); self::$memory = memory_get_usage(); self::$max = 0; register_tick_function('call_user_func_array', ['Benchmark', 'memoryTick'], []); $result = is_array($args)? call_user_func_array($function, $args): call_user_func_array($function); unregister_tick_function('call_user_func_array'); return [ 'memory' => self::$max ]; } } var_dump(Benchmark::benchmarkMemory('str_repeat', ['test',1E4])); var_dump(Benchmark::benchmarkMemory('str_repeat', ['test',1E3]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AaDUv
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_STATIC_METHOD_CALL                                  'Benchmark', '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_STATIC_METHOD_CALL                                  'Benchmark', '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

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

End of function memorytick

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

End of function benchmarkmemory

End of class Benchmark.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.86 ms | 1404 KiB | 23 Q