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:
adrian
2012-10-30 12:15:26 +00:00
parent ccc4aca728
commit dd17034fce
2 changed files with 50 additions and 52 deletions

View File

@ -8,61 +8,52 @@
namespace fail {
WallclockTimer::WallclockTimer() {
isRunning = false;
void WallclockTimer::startTimer()
{
m_IsRunning = true;
gettimeofday(&m_Start, NULL);
}
void WallclockTimer::startTimer() {
isRunning = true;
gettimeofday(&start, NULL);
}
std::string WallclockTimer::getRuntimeAsString() const {
std::string WallclockTimer::getRuntimeAsString() const
{
std::stringstream result;
result << getRuntimeAsDouble();
return result.str().c_str();
}
double WallclockTimer::getRuntimeAsDouble() const {
double WallclockTimer::getRuntimeAsDouble() const
{
double result;
struct timeval current;
if (isRunning) {
if (m_IsRunning) {
gettimeofday(&current, NULL);
result = current.tv_sec - start.tv_sec;
result = result + (((double)current.tv_usec-start.tv_usec)/1000000);
result = current.tv_sec - m_Start.tv_sec;
result = result + (((double)current.tv_usec-m_Start.tv_usec)/1000000);
} else {
result = end.tv_sec - start.tv_sec;
result = result + (((double)end.tv_usec-start.tv_usec)/1000000);
result = m_End.tv_sec - m_Start.tv_sec;
result = result + (((double)m_End.tv_usec-m_Start.tv_usec)/1000000);
}
return result;
}
void WallclockTimer::stopTimer() {
if (isRunning) {
isRunning = false;
gettimeofday(&end, NULL);
void WallclockTimer::stopTimer()
{
if (m_IsRunning) {
m_IsRunning = false;
gettimeofday(&m_End, NULL);
}
}
void WallclockTimer::reset() {
isRunning = false;
start.tv_sec = 0;
start.tv_usec = 0;
end.tv_sec = 0;
end.tv_usec = 0;
}
std::ostream& operator<< (std::ostream& os, const WallclockTimer& w) {
os << w.getRuntimeAsString();
return os;
void WallclockTimer::reset()
{
m_IsRunning = false;
m_Start.tv_sec = 0;
m_Start.tv_usec = 0;
m_End.tv_sec = 0;
m_End.tv_usec = 0;
}
} // end-of-namespace: fail

View File

@ -1,7 +1,8 @@
/**
* \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__
@ -11,51 +12,57 @@
#include <stdlib.h>
#include <sys/time.h>
namespace fail {
/**
* \class WallclockTimer
*
* The class WallclockTimer contains all functions for start, stop, reset and to get the elapsed
* time.
* The class WallclockTimer contains all functions for start,
* stop, reset and to get the elapsed time.
*/
class WallclockTimer {
private:
bool isRunning;
struct timeval start,end;
bool m_IsRunning;
struct timeval m_Start, m_End;
public:
WallclockTimer();
WallclockTimer() : m_IsRunning(false) { }
virtual ~WallclockTimer() { }
/**
* Starts the timer.
* Starts the timer.
*/
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;
/**
* 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;
/**
* Stops the timer.
* Stops the timer.
*/
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();
/**
* Returns the elapsed time as \c double. This works while the
* timer is running, and if it is stopped.
*/
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