-
+#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:
+ static TimingSingleton singleton = new TimingSingleton( );
+ int64_t startTime = 0;
+ int64_t totalTime = 0;
+
+ TimingSingleton() : startTime(0),
+ totalTime(0) {
+ }
+
+ int64_t nanoTime() {
+ int64_t time;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec*1000000000+tv.tv_usec*1000;
+ }
+
+ public:
+ void startTime() {
+ startTime = nanoTime();
+ }
+
+ void endTime() {
+ totalTime += nanoTime() - startTime;
+ }
+
+ int64_t getTime() {
+ return totalTime;
+ }
+};
+
+TimingSingleton t_singleton;
+TimingSingleton * TimingSingleton_getInstance() {
+ return &t_singleton;
}
+#endif