How to realise long-term high-resolution timing on windows using C++?

有些话、适合烂在心里 提交于 2019-11-29 07:26:19
Roman R.

Deleted article from CodeProject, this seems to be the copy: DateTimePrecise C# Class The idea is to use QueryPerformanceCounter API for accurate small increments and periodically adjust it in order to keep long term accuracy. This is about to give microsecond accuracy ("about" because it's still not exactly precise, but still quite usable).

See also: Microsecond resolution timestamps on Windows

Which language are you using?

  • In Java (1.5 or above) I'd suggest 'System.nanoTime()' which requires no import.

Remember in Windows that time-slice granularity is 1000ms / 64 = 15.625ms.

  • This will affect inter-process communication, especially on uni-processor machines, or machines that run several heavy CPU usage processes 'concurrently'*.

  • In fact, I just got DOS 6.22 and Windows for Workgroups 3.11/3.15 via eBay, so I can screenshot the original timeslice configuration for uni-processor Windows machines of the era when I started to get into it. (Although it might not be visible in versions above 3.0).

You'll be hard pressed to find anything better than QueryPerformanceTimer() on Windows.

On modern hardware it uses the HPET as a source which replaces the RTC interrupt controller. I would expect QueryPerformanceTimer() and the System clock to be synchronous.

Arno

There is no such QueryPerformanceTimer() on windows. The resource is named QueryPerformanceCounter(). It provides a counter value counting at some higher frequency. Its incrementing frequency can be retrieved by a call to QueryPerformanceFrequency(). Since this frequency is typically in the MHz range, microsecond resolution can be observed.

There are some implementations around, i.e. this thread or at the Windows Timestamp Project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!