<?php
function benchmarkMemory(callable $function, $args=null)
{
declare(ticks=1);
$memory = memory_get_usage();
$max = 0;
if(!class_exists('classWithNoName'))
{
class classWithNoName
{
public static $memory, $max;
public function __invoke()
{
self::$memory = memory_get_usage() - self::$memory;
self::$max = self::$memory>self::$max?self::$memory:self::$max;
self::$memory = memory_get_usage();
}
public function __toString()
{
return __CLASS__;
}
}
classWithNoName::$memory = memory_get_usage();
classWithNoName::$max = 0;
}
register_tick_function('classWithNoName');
$result = is_array($args)?
call_user_func_array($function, $args):
call_user_func_array($function);
unregister_tick_function('classWithNoName');
return [
'memory' => $max
];
}
var_dump(benchmarkMemory('str_repeat', ['test',1E4]));//0
var_dump(benchmarkMemory('str_repeat', ['test',1E3]));//0
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.36, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.17 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
- Warning: register_tick_function(): Invalid tick callback 'classWithNoName' passed in /in/TelNe on line 28
array(1) {
["memory"]=>
int(0)
}
Warning: register_tick_function(): Invalid tick callback 'classWithNoName' passed in /in/TelNe on line 28
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/TelNe on line 33
Process exited with code 255. - Output for 5.0.0 - 5.0.5
- Parse error: parse error, unexpected '[' in /in/TelNe on line 33
Process exited with code 255. - Output for 4.4.2 - 4.4.9
- Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/TelNe 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/TelNe on line 3
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error, expecting `')'' in /in/TelNe on line 3
Process exited with code 255.
preferences:
178.94 ms | 401 KiB | 238 Q