ctimer.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 45 行

CPP
45
字号
#include "ctimer.h"#include <time.h>void CTimer::Reset()// postcondition: all history of timer use erased//                (cumulative will return 0)     {    myCumulative = 0.0;}void CTimer::Start()// postcondition: timer started     {    myStartTime = clock();}void CTimer::Stop()// postcondition: timer stopped     {    myEndTime = clock();    myElapsed = myEndTime - myStartTime;   // time since last start    myCumulative += myElapsed;             // add to cumulative time}    double CTimer::ElapsedTime()// postcondition: returns time between last stop and start     {    return myElapsed/CLOCKS_PER_SEC;}double CTimer::CumulativeTime()// postcondition: returns time timer has been active (last stop)     {    return myCumulative/CLOCKS_PER_SEC;}CTimer::CTimer() : myElapsed(0.0), myCumulative(0.0){    static int firstTime = 0;    if (firstTime == 0){	(void) clock();       // start up clock first time	firstTime = 1;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?