Changed interface.

This commit is contained in:
Federico Ponchio 2004-07-20 14:03:47 +00:00
parent 84d5e7287b
commit f417270df1
2 changed files with 37 additions and 18 deletions

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.2 2004/07/05 15:49:39 ponchio
Windows (DevCpp, mingw) port.
Revision 1.1 2004/07/01 21:38:30 ponchio
First draft created.
@ -31,23 +34,27 @@ First draft created.
****************************************************************************/
#include "stopwatch.h"
StopWatch::StopWatch(): elapsed(0) {}
#ifdef WIN32
void StopWatch::Start(void) {
static int first = 1;
if(first) {
StopWatch::StopWatch(): elapsed(0) {
QueryPerformanceFrequency(&freq);
first = 0;
}
QueryPerformanceCounter(&tstart);
}
void StopWatch::Stop() {
#ifdef WIN32
double StopWatch::Start(void) {
QueryPerformanceCounter(&tstart);
return elapsed;
}
double StopWatch::Pause() {
QueryPerformanceCounter(&tend);
elapsed += Diff();
return elapsed;
}
double StopWatch::Elapsed() {
QueryPerformanceCounter(&tend);
return elapsed + Diff();
}
double StopWatch::Diff() {
return ((double)tend.QuadPart -
(double)tstart.QuadPart)/
@ -56,13 +63,20 @@ double StopWatch::Diff() {
#else
void StopWatch::Start() {
double StopWatch::Start() {
gettimeofday(&tstart, &tz);
return elapsed;
}
void StopWatch::Stop() {
double StopWatch::Pause() {
gettimeofday(&tend, &tz);
elapsed += Diff();
return elapsed;
}
double StopWatch::Elapsed() {
gettimeofday(&tend, &tz);
return elapsed + Diff();
}
double StopWatch::Diff() {
@ -72,12 +86,13 @@ double StopWatch::Diff() {
}
#endif
void StopWatch::Reset() {
elapsed = 0;
void StopWatch::Restart(void) {
elapsed = 0;
Start();
}
double StopWatch::Elapsed() {
return elapsed;
void StopWatch::Reset() {
elapsed = 0;
}
int StopWatch::Usec() {

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.2 2004/07/05 15:49:39 ponchio
Windows (DevCpp, mingw) port.
Revision 1.1 2004/07/01 21:38:30 ponchio
First draft created.
@ -40,8 +43,9 @@ First draft created.
class StopWatch {
public:
StopWatch();
void Start();
void Stop();
double Start();
double Pause();
void Restart();
void Reset();
double Elapsed();
int Usec();