MicroTimer class

Share your CuteNews.RU skins and code snippets.

MicroTimer class

Postby Chaser » Wed Jul 06, 2016 9:15 pm

A replacement for the microTimer class in functions.inc.php. Code improved and tightened. Adding a starttime variable is obsolete.

Code: Select all
class microTimer
{

    protected $mtime;

    /**
     * Initiate microtime
     */
    public function __construct()
    {
        $this->mtime = $this->calculate();
    }

    /**
     * Start timer
     *
     * @return type
     * @access private
     */
    protected function calculate()
    {
        $mtime = microtime();
        $mtime = explode(' ', $mtime);
        return $mtime = $mtime[1] + $mtime[0];
    }

    /**
     * Stop timer
     *
     * @return type
     * @access private
     */
    public function elapsed()
    {
        $totaltime = round($this->calculate() - $this->mtime, 5);
        return $totaltime;
    }

}


Usage example:
Code: Select all
<?php
$timer = new microTimer;

echoheader('user', $echo['header']);
?>

// Your site code...

<?php
echofooter();
?>

<!-- Page rendered in <?php echo $timer->elapsed(); ?> seconds. -->
User avatar
Chaser
 
Posts: 87
Joined: Tue Feb 17, 2009 7:26 pm

Return to Skins and snippets



Who is online

Users browsing this forum: No registered users and 1 guest

cron

x