Advertisement
Guest User

WFMO Timeout Tester

a guest
Dec 27th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. #include <windows.h>
  5.  
  6. __int64 getSystemTimeMicroseconds() {
  7. LARGE_INTEGER ticks;
  8. QueryPerformanceCounter(&ticks);
  9. return *(__int64*)&ticks;
  10. }
  11.  
  12. int main() {
  13. HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL);
  14.  
  15. const int numTrials = 100;
  16.  
  17. __int64 microsecondsLateSum = 0;
  18.  
  19. for (int i = 0; i < numTrials; i++) {
  20. __int64 timeBeforeWaitMicroseconds = getSystemTimeMicroseconds();
  21. __int64 desiredWaitMicroseconds = rand() * 1337 % 2600000 + 400000;
  22. __int64 desiredTimeAfterWaitMicroseconds = timeBeforeWaitMicroseconds + desiredWaitMicroseconds;
  23. WaitForMultipleObjects(1, &event, false, desiredWaitMicroseconds / 1000);
  24. __int64 timeAfterWaitMicroseconds = getSystemTimeMicroseconds();
  25.  
  26. __int64 microsecondsLate = timeAfterWaitMicroseconds - desiredTimeAfterWaitMicroseconds;
  27.  
  28. std::cout << "from " << timeBeforeWaitMicroseconds << " desired wait of " << desiredWaitMicroseconds << " to desired end time of " << desiredTimeAfterWaitMicroseconds << " actually ended " << timeAfterWaitMicroseconds << " late by " << microsecondsLate << " microseconds" << std::endl;
  29. microsecondsLateSum += microsecondsLate;
  30. }
  31.  
  32. std::cout << "late by on average " << microsecondsLateSum / numTrials << " microseconds" << std::endl;
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement