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
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
Warning: Parameter 1 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 17 Warning: Parameter 2 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 17 Warning: Parameter 1 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 20 Warning: Parameter 2 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 20 array(1) { ["memory"]=> int(0) } Warning: Parameter 1 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 17 Warning: Parameter 2 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 17 Warning: Parameter 1 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 20 Warning: Parameter 2 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 20 array(1) { ["memory"]=> int(0) }
Output for 7.0.0 - 7.0.33
Warning: Parameter 1 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 17 Warning: benchmarkMemory(): Unable to call functionWithNoName() - function does not exist in /in/V5f2a on line 17 Warning: Parameter 1 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 20 Warning: benchmarkMemory(): Unable to call functionWithNoName() - function does not exist in /in/V5f2a on line 20 array(1) { ["memory"]=> int(0) } Warning: Parameter 1 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 17 Warning: benchmarkMemory(): Unable to call functionWithNoName() - function does not exist in /in/V5f2a on line 17 Warning: Parameter 1 to functionWithNoName() expected to be a reference, value given in /in/V5f2a on line 20 Warning: benchmarkMemory(): Unable to call functionWithNoName() - function does not exist in /in/V5f2a on line 20 array(1) { ["memory"]=> int(0) }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
array(1) { ["memory"]=> int(0) } array(1) { ["memory"]=> int(0) }
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/V5f2a on line 22
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/V5f2a on line 22
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/V5f2a on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting ')' in /in/V5f2a on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/V5f2a on line 3
Process exited with code 255.

preferences:
225.99 ms | 401 KiB | 325 Q