-
+#ifndef TIMINGSINGLETON_H
+#define TIMINGSINGLETON_H
+#include <sys/time.h>
class TimingSingleton {
- private static TimingSingleton singleton = new TimingSingleton( );
- private static int64_t startTime = 0;
-
- private static int64_t totalTime = 0;
-
- private TimingSingleton() {
-
- }
-
- public static TimingSingleton getInstance( ) {
- return singleton;
- }
-
-
- public static void startTime( ) {
- startTime = System.nanoTime();
- }
-
- public static void endTime( ) {
- totalTime += System.nanoTime() - startTime;
-
- }
-
- public static int64_t getTime( ) {
- return totalTime;
- }
-
-
+private:
+ int64_t fldstartTime;
+ int64_t fldtotalTime;
+
+public:
+ TimingSingleton() : fldstartTime(0),
+ fldtotalTime(0) {
+ }
+
+ int64_t nanoTime() {
+ int64_t time;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
+ }
+
+ void startTime() {
+ fldstartTime = nanoTime();
+ }
+
+ void endTime() {
+ fldtotalTime += nanoTime() - fldstartTime;
+ }
+
+ int64_t getTime() {
+ return fldtotalTime;
+ }
+};
+
+TimingSingleton t_singleton;
+TimingSingleton *TimingSingleton_getInstance() {
+ return &t_singleton;
}
+#endif