Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126890
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/timedifference.cpp b/util/timedifference.cpp
index 785177b5..5bb14f50 100644
--- a/util/timedifference.cpp
+++ b/util/timedifference.cpp
@@ -1,64 +1,71 @@
#include "timedifference.h"
#include <sstream>
#include <iostream>
#include <string>
#include <math.h>
+#include "system.h"
using namespace std;
-TimeDifference::TimeDifference(){
- start.tv_usec = 0;
- start.tv_sec = 0;
- end.tv_usec = 0;
- end.tv_sec = 0;
+TimeDifference::TimeDifference():
+start(0),
+end(0){
+}
+
+void TimeDifference::startTime(){
+ start = System::currentMicroseconds();
+}
+
+void TimeDifference::endTime(){
+ end = System::currentMicroseconds();
}
const string TimeDifference::printTime(){
- return this->printTime("Function took");
+ return this->printTime("Function took");
}
unsigned long long int TimeDifference::getTime(){
- unsigned long long int g = (end.tv_sec*1000000+end.tv_usec) - (start.tv_sec*1000000 + start.tv_usec );
- return g;
+ unsigned long long int g = end - start;
+ return g;
}
static double roundit(double number, int digits){
return (long long) (number * pow((double) 10.0, digits)) / pow((double) 10.0, digits);
}
const string TimeDifference::printTime(const string & s){
- double total = (unsigned long long) (end.tv_sec*1000000+end.tv_usec) - (unsigned long long) (start.tv_sec*1000000 + start.tv_usec );
+ double total = getTime();
string units = "microseconds";
int unit_times[] = {1000, 1000, 60};
string unit_descriptions[] = {"milliseconds", "seconds", "minutes"};
for (unsigned int index = 0; index < sizeof(unit_times) / sizeof(int); index++){
if (total > unit_times[index]){
total /= unit_times[index];
units = unit_descriptions[index];
} else {
break;
}
}
ostringstream o;
o << s << " " << roundit(total, 3) << " " << units;
return o.str();
/*
unsigned long long int micro = (end.tv_sec*1000000+end.tv_usec) - (start.tv_sec*1000000 + start.tv_usec );
unsigned long long int milli = micro / 1000;
unsigned long long int sec = milli / 1000;
//cout<<s<<" took "<<micro<<" microseconds / "<< milli << " milliseconds / " <<sec<< " seconds "<< endl;
ostringstream o;
o << s <<" took "<<micro<<" microseconds / "<< milli << " milliseconds / " <<sec<< " seconds";
return o.str();
*/
}
TimeDifference::~TimeDifference(){
}
diff --git a/util/timedifference.h b/util/timedifference.h
index f41d48d6..fa358a06 100644
--- a/util/timedifference.h
+++ b/util/timedifference.h
@@ -1,37 +1,28 @@
#ifndef _time_difference_h
#define _time_difference_h
#include <time.h>
#include <sys/time.h>
#include <string>
class TimeDifference{
public:
TimeDifference();
- inline void startTime(){
- #ifndef WINDOWS
- gettimeofday( &start, NULL );
- #endif
- }
-
- inline void endTime(){
- #ifndef WINDOWS
- gettimeofday( &end, NULL );
- #endif
- }
+ void startTime();
+ void endTime();
unsigned long long int getTime();
const std::string printTime();
const std::string printTime( const std::string & s );
~TimeDifference();
protected:
- struct timeval start, end;
+ unsigned long long start, end;
};
#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 1:28 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69246
Default Alt Text
(3 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline