3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmarkMemory(callable $function, $args=null) { $memory = memory_get_peak_usage(); $result = is_array($args)? call_user_func_array($function, $args): call_user_func_array($function); return ['memory' => memory_get_peak_usage() - $memory]; } var_dump(benchmarkMemory('str_repeat', ['test',1E4])); gc_collect_cycles(); var_dump(benchmarkMemory('str_repeat', ['test',1E3]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jCUrT
function name:  (null)
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     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                                                 
   12     7        INIT_FCALL                                               'gc_collect_cycles'
          8        DO_ICALL                                                 
   13     9        INIT_FCALL                                               'var_dump'
         10        INIT_FCALL                                               'benchmarkmemory'
         11        SEND_VAL                                                 'str_repeat'
         12        SEND_VAL                                                 <array>
         13        DO_FCALL                                      0  $3      
         14        SEND_VAR                                                 $3
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function benchmarkmemory:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jCUrT
function name:  benchmarkMemory
number of ops:  24
compiled vars:  !0 = $function, !1 = $args, !2 = $memory, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    4     2        INIT_FCALL                                               'memory_get_peak_usage'
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !2, $4
    5     5        TYPE_CHECK                                  128          !1
          6      > JMPZ                                                     ~6, ->13
    6     7    >   INIT_USER_CALL                                0          'call_user_func_array', !0
          8        SEND_ARRAY                                               !1
          9        CHECK_UNDEF_ARGS                                         
         10        DO_FCALL                                      0  $7      
         11        QM_ASSIGN                                        ~8      $7
         12      > JMP                                                      ->17
    7    13    >   INIT_FCALL                                               'call_user_func_array'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $9      
         16        QM_ASSIGN                                        ~8      $9
    5    17    >   ASSIGN                                                   !3, ~8
    8    18        INIT_FCALL                                               'memory_get_peak_usage'
         19        DO_ICALL                                         $11     
         20        SUB                                              ~12     $11, !2
         21        INIT_ARRAY                                       ~13     ~12, 'memory'
         22      > RETURN                                                   ~13
    9    23*     > RETURN                                                   null

End of function benchmarkmemory

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.28 ms | 1403 KiB | 23 Q