一个不错的计时器类

 1 /* 
2 * Timer Class
3 * By Danny Battison
4 * gabehabe@hotmail.com
5 */
6
7 #include <ctime>
8
9 class CTimer
10 {
11 public: // everything is public for ease of access
12 // begin/end variables
13 clock_t begin;
14 clock_t end;
15
16 // variable declarations used for time calculation
17 double elapTicks;
18 double elapMilli, elapSeconds, elapMinutes;
19
20 // constructor
21 CTimer () {}
22 //call myTimer.begin () to begin the timer
23 void start()
24 {
25 this->begin = clock () * CLK_TCK;
26 }
27 // call myTimer.stop () to stop the timer
28 void stop ()
29 {
30 this->end = clock () * CLK_TCK; getTimes ();
31 }
32
33 // call getTimes
34 void getTimes ()
35 {
36 // variable definitions on to calculate time taken
37 this->elapTicks = this->end - this->begin; // stop the timer, and calculete the time taken
38 this->elapMilli = this->elapTicks/1000; //milliseconds from Begin to End
39 this->elapSeconds = this->elapMilli/1000; //seconds from Begin to End
40 this->elapMinutes = this->elapSeconds/60; //minutes from Begin to End
41 }
42 };

转载于:https://www.cnblogs.com/JohnShao/archive/2011/08/24/2151468.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值