- var_dump: documentation ( source)
- memory_get_peak_usage: documentation ( source)
- gc_collect_cycles: documentation ( source)
- call_user_func_array: documentation ( source)
<?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]));