diff options
author | Magnus Hagander | 2007-04-13 20:40:59 +0000 |
---|---|---|
committer | Magnus Hagander | 2007-04-13 20:40:59 +0000 |
commit | d1020db42821fcf8a9c132ddeb513b57c26120e4 (patch) | |
tree | ea878444eaa8ffeb644d2141b4cd502739a1b624 | |
parent | c48127140d73c41fc2b3e4e493513f4acfcc2b40 (diff) |
Allow \timing in psql to have a better resolution than ~15ms on Windows.
ITAGAKI Takahiro
-rw-r--r-- | src/bin/psql/common.h | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h index 0e4a7f2fc9..09e0748073 100644 --- a/src/bin/psql/common.h +++ b/src/bin/psql/common.h @@ -63,10 +63,6 @@ extern const char *session_username(void); extern char *expand_tilde(char **filename); -/* Workarounds for Windows */ -/* Probably to be moved up the source tree in the future, perhaps to be replaced by - * more specific checks like configure-style HAVE_GETTIMEOFDAY macros. - */ #ifndef WIN32 #include <sys/time.h> @@ -78,16 +74,25 @@ typedef struct timeval TimevalStruct; ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) #else +/* + * To get good resolution (better than ~15ms) on Windows, use + * the high resolution performance counters. They can't be used + * to get absolute times, but are good for measuring differences. + */ +static __inline__ double +GetTimerFrequency(void) +{ + LARGE_INTEGER f; -#include <sys/types.h> -#include <sys/timeb.h> + QueryPerformanceFrequency(&f); + return (double) f.QuadPart; +} -typedef struct _timeb TimevalStruct; +typedef LARGE_INTEGER TimevalStruct; -#define GETTIMEOFDAY(T) _ftime(T) +#define GETTIMEOFDAY(T) QueryPerformanceCounter((T)) #define DIFF_MSEC(T, U) \ - (((T)->time - (U)->time) * 1000.0 + \ - ((T)->millitm - (U)->millitm)) -#endif + (((T)->QuadPart - (U)->QuadPart) * 1000.0 / GetTimerFrequency()) +#endif /* WIN32 */ #endif /* COMMON_H */ |