summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2015-07-13 21:35:15 (GMT)
committerJason Evans <jasone@canonware.com>2015-07-13 21:35:15 (GMT)
commit8693a9ea05931e69b30d57767405436d36ed709c (patch)
treed7815a2d8430f796523e027ca0725fabd69fdfc7
parent92d72eeef0d7e08da9de1094546330d5facba11d (diff)
downloadjemalloc-8693a9ea05931e69b30d57767405436d36ed709c.zip
jemalloc-8693a9ea05931e69b30d57767405436d36ed709c.tar.gz
jemalloc-8693a9ea05931e69b30d57767405436d36ed709c.tar.bz2
Add timer support for Windows.
-rw-r--r--test/include/test/timer.h9
-rw-r--r--test/src/timer.c25
2 files changed, 24 insertions, 10 deletions
diff --git a/test/include/test/timer.h b/test/include/test/timer.h
index 9ffbaef..a7fefdf 100644
--- a/test/include/test/timer.h
+++ b/test/include/test/timer.h
@@ -7,9 +7,12 @@
&& _POSIX_MONOTONIC_CLOCK >= 0
typedef struct {
-#if JEMALLOC_CLOCK_GETTIME
- struct timespec tv0;
- struct timespec tv1;
+#ifdef _WIN32
+ FILETIME ft0;
+ FILETIME ft1;
+#elif JEMALLOC_CLOCK_GETTIME
+ struct timespec ts0;
+ struct timespec ts1;
int clock_id;
#else
struct timeval tv0;
diff --git a/test/src/timer.c b/test/src/timer.c
index 338a9ef..66b8070 100644
--- a/test/src/timer.c
+++ b/test/src/timer.c
@@ -4,12 +4,14 @@ void
timer_start(timedelta_t *timer)
{
-#if JEMALLOC_CLOCK_GETTIME
+#ifdef _WIN32
+ GetSystemTimeAsFileTime(&timer->ft0);
+#elif JEMALLOC_CLOCK_GETTIME
if (sysconf(_SC_MONOTONIC_CLOCK) <= 0)
timer->clock_id = CLOCK_REALTIME;
else
timer->clock_id = CLOCK_MONOTONIC;
- clock_gettime(timer->clock_id, &timer->tv0);
+ clock_gettime(timer->clock_id, &timer->ts0);
#else
gettimeofday(&timer->tv0, NULL);
#endif
@@ -19,8 +21,10 @@ void
timer_stop(timedelta_t *timer)
{
-#if JEMALLOC_CLOCK_GETTIME
- clock_gettime(timer->clock_id, &timer->tv1);
+#ifdef _WIN32
+ GetSystemTimeAsFileTime(&timer->ft0);
+#elif JEMALLOC_CLOCK_GETTIME
+ clock_gettime(timer->clock_id, &timer->ts1);
#else
gettimeofday(&timer->tv1, NULL);
#endif
@@ -30,9 +34,16 @@ uint64_t
timer_usec(const timedelta_t *timer)
{
-#if JEMALLOC_CLOCK_GETTIME
- return (((timer->tv1.tv_sec - timer->tv0.tv_sec) * 1000000) +
- (timer->tv1.tv_nsec - timer->tv0.tv_nsec) / 1000);
+#ifdef _WIN32
+ uint64_t t0, t1;
+ t0 = (((uint64_t)timer->ft0.dwHighDateTime) << 32) |
+ timer->ft0.dwLowDateTime;
+ t1 = (((uint64_t)timer->ft1.dwHighDateTime) << 32) |
+ timer->ft1.dwLowDateTime;
+ return ((t1 - t0) / 10);
+#elif JEMALLOC_CLOCK_GETTIME
+ return (((timer->ts1.tv_sec - timer->ts0.tv_sec) * 1000000) +
+ (timer->ts1.tv_nsec - timer->ts0.tv_nsec) / 1000);
#else
return (((timer->tv1.tv_sec - timer->tv0.tv_sec) * 1000000) +
timer->tv1.tv_usec - timer->tv0.tv_usec);