00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024
00025 #include "Clock.h"
00026
00027
00028
00029
00030 Clock::Clock()
00031 {
00032 #ifdef _WIN32
00033 ::GetLocalTime(&m_time);
00034 ::GetLocalTime(&m_time0);
00035 #else
00036 gettimeofday(&m_tv, &m_tz);
00037 gettimeofday(&m_tv0, &m_tz0);
00038 #endif
00039 }
00040
00041
00042 Clock::~Clock()
00043 {
00044 }
00045
00046
00047 void Clock::PrintDiff(const std::string& str)
00048 {
00049 #ifdef _WIN32
00050 SYSTEMTIME time;
00051 SYSTEMTIME time0;
00052 ::GetLocalTime(&time);
00053 ::GetLocalTime(&time0);
00054 time.wSecond -= m_time.wSecond;
00055 if (time.wSecond < 0)
00056 time.wSecond += 60;
00057 {
00058 time_t t = time.wSecond * 1000 + time.wMilliseconds - m_time.wMilliseconds;
00059 time_t s = t / 1000;
00060 time_t m = t % 1000;
00061 if (!str.size())
00062 printf("Time: %d.%03d", s, m);
00063 else
00064 printf("Time %s: %d.%03d", str.c_str(), s, m);
00065 }
00066 time0.wSecond -= m_time0.wSecond;
00067 if (time0.wSecond < 0)
00068 time0.wSecond += 60;
00069 {
00070 time_t t = time0.wSecond * 1000 + time0.wMilliseconds - m_time0.wMilliseconds;
00071 time_t s = t / 1000;
00072 time_t m = t % 1000;
00073 if (!str.size())
00074 printf("Time: %d.%03d", s, m);
00075 else
00076 printf("Time %s: %d.%03d", str.c_str(), s, m);
00077 }
00078 #else
00079 struct timeval tv;
00080 struct timezone tz;
00081 struct timeval tv0;
00082 struct timezone tz0;
00083 gettimeofday(&tv, &tz);
00084 gettimeofday(&tv0, &tz0);
00085 tv.tv_sec -= m_tv.tv_sec;
00086 {
00087 time_t t = tv.tv_sec * 1000000 + tv.tv_usec - m_tv.tv_usec;
00088 time_t s = t / 1000000;
00089 time_t u = t % 1000000;
00090 if (!str.size())
00091 printf("Time: %d.%06d", s, u);
00092 else
00093 printf("Time %s: %d.%06d", str.c_str(), s, u);
00094 }
00095 tv0.tv_sec -= m_tv0.tv_sec;
00096 {
00097 time_t t = tv0.tv_sec * 1000000 + tv0.tv_usec - m_tv0.tv_usec;
00098 time_t s = t / 1000000;
00099 time_t u = t % 1000000;
00100 if (!str.size())
00101 printf(" / %d.%06d", s, u);
00102 else
00103 printf(" / %d.%06d", s, u);
00104 }
00105 printf("\n");
00106 #endif
00107 Reset();
00108 }
00109
00110