3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function benchmarkMemory(callable $function, $args=null) { declare(ticks=1); global $_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
Output for 5.3.0 - 5.5.6
Parse error: syntax error, unexpected '=', expecting ',' or ';' in /in/orqSr on line 6
Process exited with code 255.