3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmarkMemory(callable $function, $args=null) { declare(ticks=1); global $_memory, $_max; $_memory = memory_get_usage(); $_max = 0; if(!function_exists('functionWithNoName')) { function functionWithNoName() { global $_memory, $_max; $_memory = memory_get_usage() - $_memory; $_max = $_memory>$_max?$_memory:$_max; $_memory = memory_get_usage(); } } register_tick_function('functionWithNoName'); $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:
32.96 ms | 402 KiB | 5 Q