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

preferences:
35.31 ms | 402 KiB | 5 Q