WallclockTimer: coding style unifications.
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1867 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
@ -8,61 +8,52 @@
|
|||||||
|
|
||||||
namespace fail {
|
namespace fail {
|
||||||
|
|
||||||
WallclockTimer::WallclockTimer() {
|
void WallclockTimer::startTimer()
|
||||||
isRunning = false;
|
{
|
||||||
|
m_IsRunning = true;
|
||||||
|
gettimeofday(&m_Start, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WallclockTimer::startTimer() {
|
std::string WallclockTimer::getRuntimeAsString() const
|
||||||
isRunning = true;
|
{
|
||||||
gettimeofday(&start, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string WallclockTimer::getRuntimeAsString() const {
|
|
||||||
|
|
||||||
std::stringstream result;
|
std::stringstream result;
|
||||||
result << getRuntimeAsDouble();
|
result << getRuntimeAsDouble();
|
||||||
|
|
||||||
return result.str().c_str();
|
return result.str().c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
double WallclockTimer::getRuntimeAsDouble() const {
|
double WallclockTimer::getRuntimeAsDouble() const
|
||||||
|
{
|
||||||
double result;
|
double result;
|
||||||
struct timeval current;
|
struct timeval current;
|
||||||
|
|
||||||
if (isRunning) {
|
if (m_IsRunning) {
|
||||||
gettimeofday(¤t, NULL);
|
gettimeofday(¤t, NULL);
|
||||||
result = current.tv_sec - start.tv_sec;
|
result = current.tv_sec - m_Start.tv_sec;
|
||||||
result = result + (((double)current.tv_usec-start.tv_usec)/1000000);
|
result = result + (((double)current.tv_usec-m_Start.tv_usec)/1000000);
|
||||||
} else {
|
} else {
|
||||||
result = end.tv_sec - start.tv_sec;
|
result = m_End.tv_sec - m_Start.tv_sec;
|
||||||
result = result + (((double)end.tv_usec-start.tv_usec)/1000000);
|
result = result + (((double)m_End.tv_usec-m_Start.tv_usec)/1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WallclockTimer::stopTimer()
|
||||||
|
{
|
||||||
void WallclockTimer::stopTimer() {
|
if (m_IsRunning) {
|
||||||
if (isRunning) {
|
m_IsRunning = false;
|
||||||
isRunning = false;
|
gettimeofday(&m_End, NULL);
|
||||||
gettimeofday(&end, NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WallclockTimer::reset() {
|
void WallclockTimer::reset()
|
||||||
isRunning = false;
|
{
|
||||||
start.tv_sec = 0;
|
m_IsRunning = false;
|
||||||
start.tv_usec = 0;
|
m_Start.tv_sec = 0;
|
||||||
end.tv_sec = 0;
|
m_Start.tv_usec = 0;
|
||||||
end.tv_usec = 0;
|
m_End.tv_sec = 0;
|
||||||
}
|
m_End.tv_usec = 0;
|
||||||
|
|
||||||
|
|
||||||
std::ostream& operator<< (std::ostream& os, const WallclockTimer& w) {
|
|
||||||
os << w.getRuntimeAsString();
|
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end-of-namespace: fail
|
} // end-of-namespace: fail
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* \brief The WallclockTimer measures the elapsed time
|
* \brief The WallclockTimer measures the elapsed time
|
||||||
*
|
*
|
||||||
* The WallclockTimer measures the time which is elapsed between start and stop of the timer.
|
* The WallclockTimer measures the time which is elapsed between start
|
||||||
|
* and stop of the timer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __WALLCLOCKTIMER_HPP__
|
#ifndef __WALLCLOCKTIMER_HPP__
|
||||||
@ -11,51 +12,57 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
|
||||||
namespace fail {
|
namespace fail {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class WallclockTimer
|
* \class WallclockTimer
|
||||||
*
|
*
|
||||||
* The class WallclockTimer contains all functions for start, stop, reset and to get the elapsed
|
* The class WallclockTimer contains all functions for start,
|
||||||
* time.
|
* stop, reset and to get the elapsed time.
|
||||||
*/
|
*/
|
||||||
class WallclockTimer {
|
class WallclockTimer {
|
||||||
private:
|
private:
|
||||||
|
bool m_IsRunning;
|
||||||
bool isRunning;
|
struct timeval m_Start, m_End;
|
||||||
struct timeval start,end;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WallclockTimer();
|
WallclockTimer() : m_IsRunning(false) { }
|
||||||
virtual ~WallclockTimer() { }
|
virtual ~WallclockTimer() { }
|
||||||
/**
|
/**
|
||||||
* Starts the timer.
|
* Starts the timer.
|
||||||
*/
|
*/
|
||||||
void startTimer();
|
void startTimer();
|
||||||
/**
|
/**
|
||||||
* Returns the elapsed time as string. This works while the timer is running, and if it is stopped.
|
* Returns the elapsed time as \c std::string. This works while the timer
|
||||||
|
* is running, and if it is stopped.
|
||||||
*/
|
*/
|
||||||
std::string getRuntimeAsString() const;
|
std::string getRuntimeAsString() const;
|
||||||
/**
|
/**
|
||||||
* Returns the elapsed time as double. This works while the timer is running, and if it is stopped.
|
* Returns the elapsed time as \c double. This works while the timer
|
||||||
|
* is running, and if it is stopped.
|
||||||
*/
|
*/
|
||||||
double getRuntimeAsDouble() const;
|
double getRuntimeAsDouble() const;
|
||||||
/**
|
/**
|
||||||
* Stops the timer.
|
* Stops the timer.
|
||||||
*/
|
*/
|
||||||
void stopTimer();
|
void stopTimer();
|
||||||
/**
|
/**
|
||||||
* Resets the timer. The timer is after a call of reset stopped.
|
* Resets the timer. The timer is stopped after calling reset().
|
||||||
*/
|
*/
|
||||||
void reset();
|
void reset();
|
||||||
|
/**
|
||||||
|
* Returns the elapsed time as \c double. This works while the
|
||||||
|
* timer is running, and if it is stopped.
|
||||||
|
*/
|
||||||
operator double() { return getRuntimeAsDouble(); }
|
operator double() { return getRuntimeAsDouble(); }
|
||||||
|
/**
|
||||||
operator int() { return ((int) getRuntimeAsDouble()); }
|
* Returns the elapsed time as \c int. This works while the timer
|
||||||
|
* is running, and if it is stopped.
|
||||||
|
*/
|
||||||
|
operator int() { return (int)getRuntimeAsDouble(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<< (std::ostream& os, const WallclockTimer& w);
|
std::ostream& operator<< (std::ostream& os, const WallclockTimer& w)
|
||||||
|
{ return os << w.getRuntimeAsString(); }
|
||||||
|
|
||||||
} // end-of-namespace: fail
|
} // end-of-namespace: fail
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user