Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fiktivkod/library/Fiktiv/Performance.php
H Hautakoski 5be4cdd82a Merge branch 'master' of git://haze.shylip.com/fiktivkod
Conflicts:
	library/Fiktiv/Performance.php
2010-09-19 16:17:47 +02:00

77 lines
1.6 KiB
PHP

<?php
class Fiktiv_Performance
{
/**
* @var float
*/
protected static $_start = null;
protected static $_end = null;
protected static $_result = null;
/**
* @var float
*/
protected static $_end = null;
/**
* @return void
*/
public static function begin()
{
self::$_start = microtime(true);
}
/**
* @return float
*/
public static function end()
{
self::$_end = microtime(true);
self::$_result = self::$_end - self::$_start;
return self::result();
}
public static function result()
{
return self::$_result;
}
public static function benchmark($function, $params = array(), $iterations = 1000, $times = 10)
{
$result = array(
'avg' => null,
'total' => null,
'max' => null,
'min' => null,
'results' => array()
);
for ($x=0;$x<$times;$x++) {
self::begin();
for ($y=0;$y<$iterations;$y++) {
call_user_func_array($function, $params);
}
$result['results'][] = self::end();
$result['total'] += self::result();
if ($result['min'] > self::result() || empty($result['min']))
$result['min'] = self::result();
if ($result['max'] < self::result())
$result['max'] = self::result();
}
$result['avg'] = array_sum($result['results']) / count($result['results']);
return $result;
}
}