VirtualBox

Ticket #12076: checkTime.cpp

File checkTime.cpp, 1.8 KB (added by florian, 11 years ago)
Line 
1// checkTime.cpp : Defines the entry point for the console application.
2//
3
4#include "stdafx.h"
5#include "windows.h"
6#include "time.h"
7
8#include <stdlib.h>
9#include <stdio.h>
10#include <conio.h>
11#include <process.h>
12
13#include <string.h>
14
15
16// DWORD WINAPI GetTickCount(void);
17
18static char * GetTimeString()
19{
20 SYSTEMTIME st;
21 GetLocalTime(&st);
22 static char to[100];
23 sprintf (to,"%d-%02d-%02d %02d:%02d:%02d.%03d", (int)st.wYear, (int)st.wMonth,(int)st.wDay,(int)st.wHour,
24 (int)st.wMinute,(int)st.wSecond,(int) st.wMilliseconds);
25 return to;
26}
27
28
29int _tmain(int argc, _TCHAR* argv[])
30{
31 DWORD lastTime=GetTickCount();
32 DWORD actTime;
33 DWORD diff;
34 LONGLONG g_Frequency, g_CurrentCount, g_LastCount;
35
36 //Frequenz holen
37 if (!QueryPerformanceFrequency((LARGE_INTEGER*)&g_Frequency))
38 printf("PerformanceCounter nicht vorhanden\n");
39
40 printf("Frequency: %llx\n", g_Frequency);
41
42 QueryPerformanceCounter((LARGE_INTEGER*)&g_LastCount);
43
44 long overflow=0xFFFFFFFF / g_Frequency;
45
46 printf("%s\n",GetTimeString());
47 printf ("Overflow from lower part are %ld seconds\n",overflow);
48 printf ("ActTime=%lx\n",lastTime);
49 printf ("ActPerfTime=%llx\n",g_LastCount);
50 for (;;)
51 {
52 Sleep(1000);
53 actTime=GetTickCount();
54 diff = actTime-lastTime;
55
56 if (diff > 2000) {
57 printf("%s: Error %ld\n", GetTimeString(), diff);
58 printf ("ActTime=%lx\n",actTime);
59 }
60 lastTime=actTime;
61 QueryPerformanceCounter((LARGE_INTEGER*)&g_CurrentCount);
62
63 double dTimeDiff = (((double)(g_CurrentCount-g_LastCount))/((double)g_Frequency));
64 if (dTimeDiff > 2 || dTimeDiff < 0) {
65 printf("%s: PerfError %f\n", GetTimeString(), dTimeDiff);
66 printf ("ActPerfTime=%llx\n",g_CurrentCount);
67 }
68 g_LastCount=g_CurrentCount;
69
70
71 }
72 return 0;
73}

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette