3 * - http://msdn.microsoft.com/en-us/library/ms644904%28VS.85%29.aspx
4 * - Python-2.6.3/Modules/timemodule.c
8 #include "hirestimeofday.h"
16 HiResTimeOfDay* HiResTimeOfDay::_instance = 0;
18 HiResTimeOfDay* HiResTimeOfDay::Instance()
21 _instance = new HiResTimeOfDay();
28 #include <sys/timeb.h>
31 HiResTimeOfDay::HiResTimeOfDay(void)
33 frequency = getFrequency();
34 epochstart = getFTime();
35 epochcounter = getCounter();
39 tint HiResTimeOfDay::getTimeUSec(void)
41 LARGE_INTEGER currentcounter;
44 currentstart = getFTime();
45 currentcounter = getCounter();
47 if (currentcounter.QuadPart < epochcounter.QuadPart)
50 // Wrap around detected, reestablish baseline
51 epochstart = currentstart;
52 epochcounter = currentcounter;
54 return epochstart + (1000000*(currentcounter.QuadPart-epochcounter.QuadPart))/frequency.QuadPart;
59 tint HiResTimeOfDay::getFTime()
64 usec = t.time * 1000000;
65 usec += t.millitm * 1000;
71 LARGE_INTEGER HiResTimeOfDay::getFrequency(void)
73 LARGE_INTEGER proc_freq;
75 if (!::QueryPerformanceFrequency(&proc_freq))
76 std::cerr << "HiResTimeOfDay: QueryPerformanceFrequency() failed";
81 LARGE_INTEGER HiResTimeOfDay::getCounter()
83 LARGE_INTEGER counter;
85 DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0);
86 if (!::QueryPerformanceCounter(&counter))
87 std::cerr << "HiResTimeOfDay: QueryPerformanceCounter() failed";
88 ::SetThreadAffinityMask(::GetCurrentThread(), oldmask);
95 HiResTimeOfDay::HiResTimeOfDay(void)
100 tint HiResTimeOfDay::getTimeUSec(void)
103 gettimeofday(&t,NULL);
115 // ARNOTODO: move to swift.cpp
118 static WSADATA _WSAData;
121 void LibraryInit(void)
124 // win32 requires you to initialize the Winsock DLL with the desired
125 // specification version
126 WORD wVersionRequested;
127 wVersionRequested = MAKEWORD(2, 2);
128 WSAStartup(wVersionRequested, &_WSAData);
133 } // end of namespace
141 using namespace swift;
145 HiResTimeOfDay *t = HiResTimeOfDay::Instance();
146 for (int i=0; i<100; i++)
148 tint st = t->getTimeUSec();
150 tint et = t->getTimeUSec();
152 std::cout << "diffxTime is " << diff << "\n";