00001 #ifndef TIME_H
00002 #define TIME_H
00003
00004 #include "platform.H"
00005
00006 #ifdef WIN32
00007
00008 inline double the_time()
00009 {
00010 LARGE_INTEGER freq, tick;
00011
00012
00013
00014 if (QueryPerformanceFrequency(&freq) && QueryPerformanceCounter(&tick))
00015 {
00016
00017
00018
00019
00020
00021
00022
00023 long double dtick = long double(tick.QuadPart);
00024 long double dfreq = long double(freq.QuadPart);
00025 return dtick/dfreq;
00026 }
00027 else
00028 {
00029 return double(GetTickCount())/1000.0;
00030 }
00031 }
00032
00033 inline double the_time_ms()
00034 {
00035 LARGE_INTEGER freq, tick;
00036
00037 if (QueryPerformanceFrequency(&freq) && QueryPerformanceCounter(&tick))
00038 {
00039 long double dtick = long double(tick.QuadPart);
00040 long double dfreq = long double(freq.QuadPart);
00041 return dtick/dfreq*1000.0;
00042
00043
00044 }
00045 else
00046 {
00047 return double(GetTickCount());
00048 }
00049 }
00050
00051 #else
00052
00053 inline double the_time()
00054 {
00055 struct timeval ts; struct timezone tz;
00056 gettimeofday(&ts, &tz);
00057 return (double)(ts.tv_sec + ts.tv_usec/1e6);
00058 }
00059 inline double the_time_ms()
00060 {
00061 struct timeval ts; struct timezone tz;
00062 gettimeofday(&ts, &tz);
00063 return (double)(ts.tv_sec*1e3 + ts.tv_usec/1e3);
00064 }
00065
00066 #endif
00067
00068 #endif