3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Benchmark { private static $max, $memory; public static function memoryTick() { self::$memory = memory_get_usage() - self::$memory; self::$max = self::$memory>self::$max?self::$memory:self::$max; self::$memory = memory_get_usage(); debug_print_backtrace(); } public static function benchmarkMemory(callable $function, $args=null) { declare(ticks=1); self::$memory = memory_get_usage(); self::$max = 0; register_tick_function('call_user_func_array', ['Benchmark', 'memoryTick'], []); $result = is_array($args)? call_user_func_array($function, $args): call_user_func_array($function); unregister_tick_function('call_user_func_array'); return [ 'memory' => self::$max ]; } } var_dump(Benchmark::benchmarkMemory('str_repeat', ['test',1E4])); var_dump(Benchmark::benchmarkMemory('str_repeat', ['test',1E3]));
Output for 7.0.0 - 7.1.0
#0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:20] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 10000)) called at [/in/Tt9Z6:30] #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:23] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 10000)) called at [/in/Tt9Z6:30] array(1) { ["memory"]=> int(40992) } #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:20] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 1000)) called at [/in/Tt9Z6:31] #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:23] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 1000)) called at [/in/Tt9Z6:31] array(1) { ["memory"]=> int(4096) }
Output for 5.6.0 - 5.6.28
#0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:20] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 10000)) called at [/in/Tt9Z6:30] #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:23] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 10000)) called at [/in/Tt9Z6:30] array(1) { ["memory"]=> int(40608) } #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:20] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 1000)) called at [/in/Tt9Z6:31] #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:23] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 1000)) called at [/in/Tt9Z6:31] array(1) { ["memory"]=> int(4560) }
Output for 5.4.0 - 5.4.9, 5.5.0 - 5.5.38
#0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:20] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 10000)) called at [/in/Tt9Z6:30] #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:23] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 10000)) called at [/in/Tt9Z6:30] array(1) { ["memory"]=> int(40616) } #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:20] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 1000)) called at [/in/Tt9Z6:31] #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:23] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 1000)) called at [/in/Tt9Z6:31] array(1) { ["memory"]=> int(4560) }
Output for 5.4.10 - 5.4.45
#0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:20] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 10000)) called at [/in/Tt9Z6:30] #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:23] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 10000)) called at [/in/Tt9Z6:30] array(1) { ["memory"]=> int(40592) } #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:20] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 1000)) called at [/in/Tt9Z6:31] #0 Benchmark::memoryTick() #1 call_user_func_array(Array ([0] => Benchmark,[1] => memoryTick), Array ()) called at [/in/Tt9Z6:23] #2 Benchmark::benchmarkMemory(str_repeat, Array ([0] => test,[1] => 1000)) called at [/in/Tt9Z6:31] array(1) { ["memory"]=> int(4560) }
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Tt9Z6 on line 20
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/Tt9Z6 on line 20
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Tt9Z6 on line 4
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 T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Tt9Z6 on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/Tt9Z6 on line 4
Process exited with code 255.