3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmarkMemory(callable $function, $args=null) { declare(ticks=1); if(!class_exists('classWithNoName')) { class classWithNoName { public static $memory, $max; } function functionWithNoName() { classWithNoName::$memory = memory_get_usage() - classWithNoName::$memory; classWithNoName::$max = classWithNoName::$memory>classWithNoName::$max? classWithNoName::$memory: classWithNoName::$max; classWithNoName::$memory = memory_get_usage(); } classWithNoName::$memory = memory_get_usage(); classWithNoName::$max = 0; } register_tick_function('functionWithNoName'); $result = is_array($args)? call_user_func_array($function, $args): call_user_func_array($function); unregister_tick_function('functionWithNoName'); $memory = classWithNoName::$max; classWithNoName::$max = 0; return [ 'memory' => $memory ]; } var_dump(benchmarkMemory('str_repeat', ['test',1E4]));//40068 var_dump(benchmarkMemory('str_repeat', ['test',1E3]));//4040
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
array(1) { ["memory"]=> int(40960) } array(1) { ["memory"]=> int(4096) }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
array(1) { ["memory"]=> int(40120) } array(1) { ["memory"]=> int(4072) }
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/bQqGA on line 30
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/bQqGA on line 30
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/bQqGA on line 2
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/bQqGA on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/bQqGA on line 2
Process exited with code 255.

preferences:
250.81 ms | 401 KiB | 317 Q