What exactly is the clock accuracy of Windows?

yl yan 0 Reputation points
2024-01-23T03:56:39.0233333+00:00

I want to measure the duration of a very short process by getting the two timestamps before and after and calculating their difference, specifically by calling Python's time.perf_counter_ns()/process_time_ns()/thread_time_ns(), which are able to get to the ns level, but clearly doesn't mean it can reach ns level precision (Windows is not RTOS), so I'm wondering, what precision can Windows reach? Thank you very much! 我要测量一个很短过程所持续的时间,方法是获取前后两个时间戳,计算它们的差值,具体来说是调用Python的time.perf_counter_ns()/process_time_ns()/thread_time_ns(),这些函数虽然能够获取到ns级别,但是显然不代表能够达到ns级别的精度(Windows不是RTOS),所以我想知道,Windows能够达到什么精度?非常感谢!

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. yl yan 0 Reputation points
    2024-01-23T05:02:10.4433333+00:00

    The programming language is secondary, the first thing I want to confirm is the precision that the Windows system itself can achieve. how much precision can the Windows API functions QueryPerformanceFrequency() and QueryPerformanceCounter() achieve? 编程语言是其次,首先是想确认Windows系统本身能达到的精度。Windows API函数QueryPerformanceFrequency()和QueryPerformanceCounter()又能达到多少精度?

    0 comments No comments

  2. Anonymous
    2024-01-24T06:53:26.2566667+00:00

    Hi yl yan,

    QueryPerformanceCounter gets time stamps in ticks, which are provided by a hardware tick generator. QueryPerformanceFrequency retrieves the number of ticks per second from the hardware tick generator at system boot. The tick resolution is the reciprocal of the frequency.

    Refer to this link for more details. https://learn.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps#resolution-precision-accuracy-and-stability

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.