wysota: I want to do a kind of portable and accurate gettimeofday();
Here is the solution, in case someone wants to do the same one day.
No garantie on it but it seems to work.
Windows part for a portable gettimeofday():
#ifdef _WIN32_
#include <windows.h>
int gettimeofday( struct timeval *tv, struct timezone *tz )
{
time_t rawtime;
time(&rawtime);
tv->tv_sec = (long)rawtime;
// here starts the microsecond resolution:
LARGE_INTEGER tickPerSecond;
LARGE_INTEGER tick; // a point in time
// get the high resolution counter's accuracy
QueryPerformanceFrequency(&tickPerSecond);
// what time is it ?
QueryPerformanceCounter(&tick);
// and here we get the current microsecond! \o/
tv->tv_usec = (tick.QuadPart % tickPerSecond.QuadPart);
return 0;
}
#endif // _WIN32_
#ifdef _WIN32_
#include <windows.h>
int gettimeofday( struct timeval *tv, struct timezone *tz )
{
time_t rawtime;
time(&rawtime);
tv->tv_sec = (long)rawtime;
// here starts the microsecond resolution:
LARGE_INTEGER tickPerSecond;
LARGE_INTEGER tick; // a point in time
// get the high resolution counter's accuracy
QueryPerformanceFrequency(&tickPerSecond);
// what time is it ?
QueryPerformanceCounter(&tick);
// and here we get the current microsecond! \o/
tv->tv_usec = (tick.QuadPart % tickPerSecond.QuadPart);
return 0;
}
#endif // _WIN32_
To copy to clipboard, switch view to plain text mode
Bookmarks