/** * Profiles a function. * * This function prints a string with function name, average run time and maximum memory usage. * * Please be aware that the maximum memory is the memory allocated to the PHP process and not necessarily for the function itself. * * @param string|array $function the function name * @param array $args the function arguments * @param number $runs the number of runs * @return string a human readable string describing the result */ public static function profileFunction($function, $args = array(), $runs = 1000) { $remaining = $runs; $total = 0; $profiler = new Profiler(); while ($remaining > 0) { call_user_func_array($function, $args); $remaining--; } $maxMemory = $profiler->getMaxMemory(); $time = $profiler->getTime(); $text = new Text(); $average = $text->convertSeconds($time / (double) $runs); $maxMemory = $text->convertBytes($maxMemory); return "Function [{$function}] avg. time: {$average[0]} {$average[1]}, max. memory: {$maxMemory[0]} {$maxMemory[1]}"; }
/** * Tests the seconds conversion. * * @dataProvider convertSecondsProvider * @covers empire\framework\util\Text::convertSeconds * * @param $seconds the seconds to convert * @param $name whether to use the full name * @param $res the result */ public function testConvertSeconds($seconds, $name, $res) { $this->assertSame($res, $this->instance->convertSeconds($seconds, $name)); }