WallclockTimer updated
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1708 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
@ -15,10 +15,11 @@ void WallclockTimer::startTimer() {
|
||||
gettimeofday(&start, NULL);
|
||||
}
|
||||
|
||||
std::string WallclockTimer::getRuntimeAsString() {
|
||||
std::string WallclockTimer::getRuntimeAsString() const {
|
||||
|
||||
int length;
|
||||
long t1,t2, duration;
|
||||
struct timeval current;
|
||||
std::stringstream lengthinfo, resultstring;
|
||||
|
||||
if (isRunning) {
|
||||
@ -33,7 +34,7 @@ std::string WallclockTimer::getRuntimeAsString() {
|
||||
duration = t2-t1;
|
||||
lengthinfo << duration-((duration/1000000)*1000000);
|
||||
length = lengthinfo.str().length();
|
||||
resultstring << (int) duration/1000000 << ".";
|
||||
resultstring << (int) duration/1000000 << ",";
|
||||
|
||||
if (length < 6) {
|
||||
int i;
|
||||
@ -46,37 +47,8 @@ std::string WallclockTimer::getRuntimeAsString() {
|
||||
return resultstring.str();
|
||||
}
|
||||
|
||||
double WallclockTimer::getRuntimeAsDouble() {
|
||||
|
||||
int length;
|
||||
long t1,t2, duration;
|
||||
double resultdouble;
|
||||
std::stringstream lengthinfo, resultstring;
|
||||
|
||||
if (isRunning) {
|
||||
gettimeofday(¤t, NULL);
|
||||
t1 = (start.tv_sec*1000000)+start.tv_usec;
|
||||
t2 = (current.tv_sec*1000000)+current.tv_usec;
|
||||
} else {
|
||||
t1 = (start.tv_sec*1000000)+start.tv_usec;
|
||||
t2 = (end.tv_sec*1000000)+end.tv_usec;
|
||||
}
|
||||
|
||||
duration = t2-t1;
|
||||
lengthinfo << duration-((duration/1000000)*1000000);
|
||||
length = lengthinfo.str().length();
|
||||
resultstring << (int) duration/1000000 << ".";
|
||||
|
||||
if (length < 6) {
|
||||
int i;
|
||||
for (i = 0 ; i< 6-length ; i++){
|
||||
resultstring << "0";
|
||||
}
|
||||
}
|
||||
|
||||
resultstring << (int) duration-((duration/1000000)*1000000);
|
||||
resultdouble = atof( resultstring.str().c_str() );
|
||||
return resultdouble;
|
||||
double WallclockTimer::getRuntimeAsDouble() const {
|
||||
return atof(getRuntimeAsString().c_str());
|
||||
}
|
||||
|
||||
|
||||
@ -92,10 +64,14 @@ void WallclockTimer::reset() {
|
||||
isRunning = false;
|
||||
start.tv_sec = 0;
|
||||
start.tv_usec = 0;
|
||||
current.tv_sec = 0;
|
||||
current.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;
|
||||
}
|
||||
|
||||
} // end-of-namespace: fail
|
||||
|
||||
Reference in New Issue
Block a user