Windows C++ nanosecond timing?

后端 未结 4 588
星月不相逢
星月不相逢 2021-01-14 12:36

Is there a way in C++ on windows to measure time in nanoseconds?

All i can find are linux solutions.

4条回答
  •  孤独总比滥情好
    2021-01-14 12:49

    If you can run your own assembly, you could read the CPU's cycle counter and divide a cycle difference it by the CPU's clock rate:

    static inline uint64_t get_cycles()
    {
      uint64_t t;
      __asm__ __volatile__ ("rdtsc" : "=A"(t));
      return t;
    }
    

提交回复
热议问题