00001
00002
00003
00004
00005
00006 #ifndef SYNAPS_UTIL_CLOCK_H
00007 #define SYNAPS_UTIL_CLOCK_H
00008
00009
00010
00011 #include <ctime>
00012 #include <synaps/init.h>
00013
00014 __BEGIN_NAMESPACE_SYNAPS
00015
00016 class Clock
00017 {
00018 public:
00019
00020
00021
00022 Clock() : start_(clock()), running(true) {};
00023
00024 ~Clock() {};
00025
00026
00027
00028 void start()
00029 {
00030 start_ = clock();
00031 running = true;
00032 }
00033
00034
00035
00036
00037 void stop()
00038 {
00039 stop_ = clock();
00040 running = false;
00041 }
00042
00043
00044
00045
00046 double time()
00047 {
00048 if (running)
00049 return double(clock() - start_) / CLOCKS_PER_SEC;
00050 else
00051 return double(stop_ - start_) / CLOCKS_PER_SEC;
00052 }
00053
00054 private:
00055 clock_t start_;
00056 clock_t stop_;
00057 bool running;
00058 };
00059
00060 __END_NAMESPACE_SYNAPS
00061
00062 #endif // SYNAPS_UTIL_CLOCK_H
00063