Increased precision of StopWatch class, no Issue
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
#ifndef STOPWATCH_H
|
#ifndef STOPWATCH_H
|
||||||
#define STOPWATCH_H
|
#define STOPWATCH_H
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/time.h>
|
#include "mytime.h"
|
||||||
|
|
||||||
class StopWatch {
|
class StopWatch {
|
||||||
public:
|
public:
|
||||||
@@ -31,14 +31,13 @@ public:
|
|||||||
~StopWatch() { if(!stopped) stop(); }
|
~StopWatch() { if(!stopped) stop(); }
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
gettimeofday(&startStruct,NULL);
|
startTime.set();
|
||||||
};
|
};
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
gettimeofday(&stopStruct,NULL);
|
stopTime.set();
|
||||||
long elapsedTime = (stopStruct.tv_sec - startStruct.tv_sec) * 1000.0; // sec to ms
|
long elapsedTime = stopTime.etime(startTime) / 1000;
|
||||||
elapsedTime += (stopStruct.tv_usec - startStruct.tv_usec)/1000;
|
std::cout << message << " took " << elapsedTime << " ms" <<std::endl;
|
||||||
std::cout << message << " took " << elapsedTime << "ms" <<std::endl;
|
|
||||||
stopped = true;
|
stopped = true;
|
||||||
}
|
}
|
||||||
void stop(const char *msg)
|
void stop(const char *msg)
|
||||||
@@ -47,8 +46,8 @@ public:
|
|||||||
stop();
|
stop();
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
struct timeval startStruct;
|
MyTime startTime;
|
||||||
struct timeval stopStruct;
|
MyTime stopTime;
|
||||||
const char *message;
|
const char *message;
|
||||||
bool stopped;
|
bool stopped;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user