# HG changeset patch # User deba # Date 1143807126 0 # Node ID 119db4e6ab2c059b7c71685aa44b5cc6b26f3824 # Parent 8d49961ec50fa23e9e72d8003fa0af7fc564288e MinGW compatibility fix diff -r 8d49961ec50f -r 119db4e6ab2c lemon/time_measure.h --- a/lemon/time_measure.h Fri Mar 31 12:04:48 2006 +0000 +++ b/lemon/time_measure.h Fri Mar 31 12:12:06 2006 +0000 @@ -23,8 +23,80 @@ ///\file ///\brief Tools for measuring cpu usage + +#ifdef WIN32 + +#include +#include +#include "dos.h" + +int gettimeofday(struct timeval * tp, struct timezone *) { + SYSTEMTIME systime; + + if (tp) { + + struct tm tmrec; + time_t theTime = time(NULL); + + tmrec = *localtime(&theTime); + tp->tv_sec = mktime(&tmrec); + GetLocalTime(&systime); /* system time */ + + tp->tv_usec = systime.wMilliseconds * 1000; + + } + + return 0; + +} + +struct tms { + long tms_utime; + long tms_stime; + long tms_cutime; + long tms_cstime; +}; + +static long filetime_to_clock(FILETIME *ft) +{ + __int64 qw = ft->dwHighDateTime; + qw <<= 32; + qw |= ft->dwLowDateTime; + qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */ + return (long) qw; + +} + +int times(struct tms *tmbuf) +{ + FILETIME create, exit, kernel, user; + if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { + tmbuf->tms_utime = filetime_to_clock(&user); + tmbuf->tms_stime = filetime_to_clock(&kernel); + tmbuf->tms_cutime = 0; + tmbuf->tms_cstime = 0; + } + else { + tmbuf->tms_utime = clock(); + tmbuf->tms_stime = 0; + tmbuf->tms_cutime = 0; + tmbuf->tms_cstime = 0; + } + return 0; +} + +#define _SC_CLK_TCK 1 + +int sysconf(int) +{ + return 1; +} + +#else +#include +#endif + #include -#include #include #include #include @@ -510,7 +582,7 @@ template TimeStamp runningTimeTest(F f,double min_time=10,int *num = NULL, - TimeStamp *full_time=NULL) + TimeStamp *full_time=NULL) { Timer t; TimeStamp full;