From e1000eb6be4e847ac7d1099c5b919a0732276a9a Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 5 Jan 2007 12:40:05 +0000 Subject: [PATCH] win32 get real implemented (timings that is). --- src/timing.c | 32 +++++++++++++++++++++++++++++--- test/tst_timing.c | 8 +++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/timing.c b/src/timing.c index 31f1095..0276d07 100644 --- a/src/timing.c +++ b/src/timing.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: timing.c,v 1.2 2007-01-05 11:44:49 adam Exp $ + * $Id: timing.c,v 1.3 2007-01-05 12:40:05 adam Exp $ */ /** @@ -14,6 +14,9 @@ #include #endif +#ifdef WIN32 +#include +#endif #include #if HAVE_SYS_TIMES_H @@ -34,6 +37,9 @@ struct yaz_timing { #if HAVE_SYS_TIME_H struct timeval start_time, end_time; #endif +#ifdef WIN32 + ULONGLONG start_time, end_time; +#endif double real_sec, user_sec, sys_sec; }; @@ -44,6 +50,19 @@ yaz_timing_t yaz_timing_create(void) return t; } +#ifdef WIN32 +static void get_date_as_largeinteger(ULONGLONG *lp) +{ + FILETIME f; + ULARGE_INTEGER li; + GetSystemTimeAsFileTime(&f); + li.LowPart = f.dwLowDateTime; + li.HighPart = f.dwHighDateTime; + + *lp = li.QuadPart; +} +#endif + void yaz_timing_start(yaz_timing_t t) { #if HAVE_SYS_TIMES_H @@ -54,11 +73,14 @@ void yaz_timing_start(yaz_timing_t t) t->user_sec = -1.0; t->sys_sec = -1.0; #endif + t->real_sec = -1.0; #if HAVE_SYS_TIME_H gettimeofday(&t->start_time, 0); t->real_sec = 0.0; -#else - t->real_sec = -1.0; +#endif +#ifdef WIN32 + get_date_as_largeinteger(&t->start_time); + t->real_sec = 0.0; #endif } @@ -76,6 +98,10 @@ void yaz_timing_stop(yaz_timing_t t) t->end_time.tv_usec - t->start_time.tv_usec) / 1000000; #endif +#ifdef WIN32 + get_date_as_largeinteger(&t->end_time); + t->real_sec = (double) (t->end_time - t->start_time) / 10000000.0; +#endif } double yaz_timing_get_real(yaz_timing_t t) diff --git a/test/tst_timing.c b/test/tst_timing.c index c02f03c..43e62ff 100644 --- a/test/tst_timing.c +++ b/test/tst_timing.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tst_timing.c,v 1.1 2007-01-05 11:45:11 adam Exp $ + * $Id: tst_timing.c,v 1.2 2007-01-05 12:40:05 adam Exp $ */ #include @@ -11,6 +11,9 @@ #include #include #include +#ifdef WIN32 +#include +#endif static void tst(void) { @@ -22,6 +25,9 @@ static void tst(void) if (!t) return; +#ifdef WIN32 + Sleep(100); +#endif for (i = 0; i<100000; i++) ; -- 1.7.10.4