如何将定时器分辨率设置为0.5 ms?
我想将机器计时器分辨率设置为 0.5ms。
Sysinternal 实用程序报告最小时钟分辨率为 0.5ms,因此可以完成。
PS我知道如何将其设置为1ms。
PPS 我将其从 C# 更改为更一般的问题(感谢 Hans)
系统计时器分辨率
I want to set a machine timer resolution to 0.5ms.
Sysinternal utility reports that the min clock resolution is 0.5ms so it can be done.
P.S. I know how to set it to 1ms.
P.P.S. I changed it from C# to more general question (thanks to Hans)
System timer resolution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
NtSetTimerResolution
示例代码:
链接 <代码>ntdll.lib。
NtSetTimerResolution
Example code:
Link with
ntdll.lib
.您可以通过隐藏的 API
NtSetTimerResolution()
获得 0.5 毫秒的分辨率。NtSetTimerResolution 由本机 Windows NT 库 NTDLL.DLL 导出。请参阅如何将计时器分辨率设置为 0.5ms? 在 MSDN 上。然而,真正可实现的分辨率是由底层硬件决定的。现代硬件确实支持 0.5 毫秒分辨率。
更多详细信息请参阅Windows NT 高分辨率定时器内部。可以通过调用 NtQueryTimerResolution() 来获取支持的分辨率。
如何做:
注意:NtSetTImerResolution 的功能基本上通过使用以下函数映射到函数
timeBeginPeriod
和timeEndPeriod
布尔值设置
(请参阅Windows NT 高分辨率内部计时器了解有关该方案及其所有影响的更多详细信息)。然而,多媒体套件将粒度限制为毫秒,并且 NtSetTimerResolution 允许设置亚毫秒值。You may obtain 0.5 ms resolution by means of the hidden API
NtSetTimerResolution()
.NtSetTimerResolution is exported by the native Windows NT library NTDLL.DLL. See How to set timer resolution to 0.5ms ? on MSDN. Nevertheless, the true achievable resoltion is determined by the underlying hardware. Modern hardware does support 0.5 ms resolution.
Even more details are found in Inside Windows NT High Resolution Timers. The supported resolutions can be obtained by a call to NtQueryTimerResolution().
How to do:
Note: The functionality of NtSetTImerResolution is basically mapped to the functions
timeBeginPeriod
andtimeEndPeriod
by using the bool valueSet
(see Inside Windows NT High Resolution Timers for more details about the scheme and all its implications). However, the multimedia suite limits the granularity to milliseconds and NtSetTimerResolution allows to set sub-millisecond values.如果你使用Python,我写了一个名为wres的库,它在内部调用NtSetTimerResolution。
pip 安装 wres
If you use python, I wrote a library named wres, which calls NtSetTimerResolution internally.
pip install wres
使用 timeBeginPeriod 和 timeSetEvent,您可以从 Win32 API 得到的最好时间是一毫秒。也许你的 HAL 可以做得更好,但那是学术性的,你不能用 C# 编写设备驱动程序代码。
The best you can get out the Win32 API is one millisecond with timeBeginPeriod and timeSetEvent. Maybe your HAL can do better but that's academic, you cannot write device driver code in C#.
您需要一个高分辨率计时器。您可以在这里找到一些信息:http ://www.codeproject.com/KB/cs/highperformancetimercshar.aspx
编辑:更多信息可以在这里找到:设置为毫秒的十分之一; http://msdn.microsoft.com/en-us /library/aa964692(VS.80).aspx
You'll need a high resolution timer for it.. You can find some information here: http://www.codeproject.com/KB/cs/highperformancetimercshar.aspx
EDIT: More information can be found here: set to tenth of millisecond; http://msdn.microsoft.com/en-us/library/aa964692(VS.80).aspx