Files
2024-10-25 14:16:28 +02:00

66 lines
1.5 KiB
PHP

<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
class PShow_Timer
{
private $start = null;
private $finish = null;
private static $instance = null;
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new PShow_Timer();
}
return self::$instance;
}
public function getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float) $usec + (float) $sec);
}
public function start()
{
$this->start = $this->getmicrotime();
return $this;
}
public function finish()
{
$this->finish = $this->getmicrotime();
return $this;
}
public function getElapsedTime($precision = false, $forcePrecisionLength = true)
{
if ($this->start === null) {
return 0;
}
$time = $this->getmicrotime() - $this->start;
if (is_numeric($precision)) {
$time = round($time, $precision);
}
if ($forcePrecisionLength) {
$adjustedLeadingZeros = 0 + mb_strlen('.') + $precision;
return sprintf("%0" . $adjustedLeadingZeros . "." . $precision . "f", $time);
}
return $time;
}
}