Advertisement
C0BRA

Here

May 19th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. double GetSeconds();
  2. {
  3. LARGE_INTEGER t;
  4. FILETIME f;
  5. double microseconds;
  6. static LARGE_INTEGER offset;
  7. static double FrequencyToMicroseconds;
  8. static int initialized = 0;
  9. static BOOL UsePerformanceCounter = 0;
  10.  
  11. if ( !initialized )
  12. {
  13. LARGE_INTEGER performanceFrequency;
  14. initialized = 1;
  15. UsePerformanceCounter = QueryPerformanceFrequency( &performanceFrequency );
  16. if ( UsePerformanceCounter )
  17. {
  18. QueryPerformanceCounter( &offset );
  19. FrequencyToMicroseconds = ( double )performanceFrequency.QuadPart / 1000000.;
  20. }
  21. else
  22. {
  23. offset = getFILETIMEoffset();
  24. FrequencyToMicroseconds = 10.;
  25. }
  26. }
  27. if ( UsePerformanceCounter )
  28. QueryPerformanceCounter( &t );
  29. else
  30. {
  31. GetSystemTimeAsFileTime( &f );
  32. t.QuadPart = f.dwHighDateTime;
  33. t.QuadPart <<= 32;
  34. t.QuadPart |= f.dwLowDateTime;
  35. }
  36.  
  37. t.QuadPart -= offset.QuadPart;
  38. microseconds = ( double )t.QuadPart / FrequencyToMicroseconds;
  39. t.QuadPart = microseconds;
  40. tv->tv_sec = t.QuadPart / 1000000;
  41. tv->tv_usec = t.QuadPart % 1000000;
  42.  
  43. return (double)(tv->tv_nsec / CLOCKS_PER_SEC) / 1000.0 + (double)tv->tv_sec;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement