您的位置:首页 > 其它

一个不错的计时器类

2011-08-24 04:24 148 查看
/*
* Timer Class
* By Danny Battison
* gabehabe@hotmail.com
*/

#include <ctime>

class CTimer
{
public: // everything is public for ease of access
// begin/end variables
clock_t begin;
clock_t end;

// variable declarations used for time calculation
double elapTicks;
double elapMilli, elapSeconds, elapMinutes;

// constructor
CTimer () {}
//call myTimer.begin () to begin the timer
void start()
{
this->begin = clock () * CLK_TCK;
}
// call myTimer.stop () to stop the timer
void stop ()
{
this->end   = clock () * CLK_TCK; getTimes ();
}

// call getTimes
void getTimes ()
{
// variable definitions on to calculate time taken
this->elapTicks   = this->end - this->begin; // stop the timer, and calculete the time taken
this->elapMilli   = this->elapTicks/1000;     //milliseconds from Begin to End
this->elapSeconds = this->elapMilli/1000;   //seconds from Begin to End
this->elapMinutes = this->elapSeconds/60;   //minutes from Begin to End
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: