diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/Utils/Timer.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/src/Utils/Timer.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/Utils/Timer.php b/www/wiki/extensions/SemanticMediaWiki/src/Utils/Timer.php new file mode 100644 index 00000000..c9871e30 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/src/Utils/Timer.php @@ -0,0 +1,72 @@ +<?php + +namespace SMW\Utils; + +/** + * @license GNU GPL v2+ + * @since 2.5 + * + * @author mwjames + */ +class Timer { + + /** + * @var float|integer + */ + private static $start = []; + + /** + * @since 3.0 + * + * @param integer $outputType + * @param integer $ts + * + * @return string|bool + */ + public static function getTimestamp( $outputType = TS_UNIX, $ts = 0 ) { + return wfTimestamp( $outputType, $ts ); + } + + /** + * @since 2.5 + */ + public static function start( $name ) { + self::$start[$name] = microtime( true ); + } + + /** + * @since 2.5 + * + * @param string $name + * @param integer|null $round + * + * @return float|integer + */ + public static function getElapsedTime( $name, $round = null ) { + + if ( !isset( self::$start[$name] ) ) { + return 0; + } + + $time = microtime( true ) - self::$start[$name]; + + if ( $round === null ) { + return $time; + } + + return round( $time, $round ); + } + + /** + * @since 3.0 + * + * @param string $name + * @param integer|null $round + * + * @return string + */ + public static function getElapsedTimeAsLoggableMessage( $name, $round = null ) { + return $name . ' (procTime in sec: '. self::getElapsedTime( $name, $round ) . ')'; + } + +} |