pctimer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00039 #ifndef _PCTIMER_H
00040
00041 typedef double pctimer_t;
00042
00043 #if defined(_WIN32) || defined(__CYGWIN__)
00044
00045 #ifndef _WIN32
00046 #define _PCTIMER_NO_WIN32
00047 #endif
00048
00049 #ifndef WIN32_LEAN_AND_MEAN
00050 #define WIN32_LEAN_AND_MEAN
00051 #endif
00052 #include <windows.h>
00053
00054 #ifdef _PCTIMER_NO_WIN32
00055 #undef _PCTIMER_NO_WIN32
00056 #undef _WIN32
00057 #endif
00058
00059 __inline pctimer_t pctimer(void)
00060 {
00061 static LARGE_INTEGER __pcount, __pcfreq;
00062 static int __initflag;
00063
00064 if (!__initflag)
00065 {
00066 QueryPerformanceFrequency(&__pcfreq);
00067 __initflag++;
00068 }
00069
00070 QueryPerformanceCounter(&__pcount);
00071 return (double)__pcount.QuadPart / (double)__pcfreq.QuadPart;
00072 }
00073
00074 #else
00075
00076 #include <sys/time.h>
00077
00078 __inline pctimer_t pctimer(void)
00079 {
00080 struct timeval __tv;
00081 gettimeofday(&__tv, NULL);
00082 return (double)__tv.tv_sec + (double)__tv.tv_usec / 1000000;
00083 }
00084
00085 #endif
00086
00087 #endif