最快的定时分辨率系统 [英] Fastest timing resolution system
问题描述
什么是最快的计时系统中的C / C ++程序员可以使用?
例如:结果
时间()将给秒自1970年1月1日00:00。结果
的GetTickCount()在Windows会给时间,以毫秒为单位,因为系统的启动时间,但仅限49.7天(这只是包装回零后)。
我想获得当前时间,或因为系统/应用程序的启动时间刻度,以毫秒为单位。
最大的担忧是该方法的开销 - 我需要最轻的一个,因为我即将把它称为很多很多次每秒
。我的情况是,我有一个工作线程,并且该工作线程我张贴的暂挂作业。每个职业都有一个执行时间。所以,我不在乎,如果时间是当前的真正的时间或因为系统的正常运行时间 - 它只是必须是线性光
。编辑:
无符号__int64 GetTickCountEx()
{
静态DWORD dwWraps = 0;
静态DWORD dwLast = 0; DWORD dwCurrent = 0; timeMutex.lock(); dwCurrent =的GetTickCount();
如果(dwLast> dwCurrent)
dwWraps ++; dwLast = dwCurrent; 无符号__int64 timeResult =((无符号__int64)0xFFFFFFFF的* dwWraps)+ dwCurrent; timeMutex.unlock(); 返回timeResult;
}
有关计时,目前微软推荐是使用<一个href=\"http://msdn.microsoft.com/en-us/library/ms886788.aspx\"><$c$c>QueryPerformanceCounter$c$c> &安培; <一href=\"http://msdn.microsoft.com/en-us/library/ms886788.aspx\"><$c$c>QueryPerformanceFrequency$c$c>.
这会给你优于毫秒的时间。如果系统不支持高分辨率定时器,那么它会默认为毫秒(同为的GetTickCount
)。
What is the fastest timing system a C/C++ programmer can use?
For example:
time() will give the seconds since Jan 01 1970 00:00.
GetTickCount() on Windows will give the time, in milliseconds, since the system's start-up time, but is limited to 49.7 days (after that it simply wraps back to zero).
I want to get the current time, or ticks since system/app start-up time, in milliseconds.
The biggest concern is the method's overhead - I need the lightest one, because I'm about to call it many many times per second.
My case is that I have a worker thread, and to that worker thread I post pending jobs. Each job has an "execution time". So, I don't care if the time is the current "real" time or the time since the system's uptime - it just must be linear and light.
Edit:
unsigned __int64 GetTickCountEx()
{
static DWORD dwWraps = 0;
static DWORD dwLast = 0;
DWORD dwCurrent = 0;
timeMutex.lock();
dwCurrent = GetTickCount();
if(dwLast > dwCurrent)
dwWraps++;
dwLast = dwCurrent;
unsigned __int64 timeResult = ((unsigned __int64)0xFFFFFFFF * dwWraps) + dwCurrent;
timeMutex.unlock();
return timeResult;
}
For timing, the current Microsoft recommendation is to use QueryPerformanceCounter
& QueryPerformanceFrequency
.
This will give you better-than-millisecond timing. If the system doesn't support a high-resolution timer, then it will default to milliseconds (the same as GetTickCount
).
Here is a short Microsoft article with examples of why you should use it :)
这篇关于最快的定时分辨率系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!