[Python] Why can consecutive calls to perf_counter_ns on windows return the same number?

Discussão em 'Python' iniciado por Stack, Agosto 18, 2025.

  1. Stack

    Stack Membro Participativo

    Using the below code I would have assumed so see cnt be close to 0, but on Windows I see only values above 500,000.

    from time import *

    def test_time(f, c):
    cnt = 0
    for i in range(c):
    ps, ts = f(), f()
    if not ps - ts:
    cnt += 1
    return cnt


    if __name__ == '__main__':
    res = test_time(perf_counter_ns, 1_000_000)
    print(res) # usually returns a count of over 500k


    On Linux this does not happen. I understand that the output resolution on Windows is limited to 100 ns increments. My question if I am missing something here or if there is a way this can be made to work on Windows.

    Continue reading...

Compartilhe esta Página