3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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
Output for 7.0.0 - 7.1.0
array(1) { ["memory"]=> int(40960) } array(1) { ["memory"]=> int(4096) }
Output for hhvm-3.10.0 - 3.12.0
Fatal error: Call to undefined function register_tick_function() in /in/OPrPa on line 19
Process exited with code 255.
Output for 5.4.0 - 5.6.28
array(1) { ["memory"]=> int(40072) } array(1) { ["memory"]=> int(4072) }
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/OPrPa on line 24
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/OPrPa on line 24
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/OPrPa on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting ')' in /in/OPrPa on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/OPrPa on line 3
Process exited with code 255.