Calculating time by the C++ code

后端 未结 7 787
囚心锁ツ
囚心锁ツ 2021-01-02 22:21

I know this question has been asked few times over SO but none of them is really helping me out, so asking again.

I am using windows xp and running visual studio c++

7条回答
  •  -上瘾入骨i
    2021-01-02 23:05

    You need a high precision timer. In case of Visual Studio use QueryPerformanceCounter.

    If the precision is still not enough, use compiler intristics:

    #include 
    #pragma intrinsic(__rdtsc)
    
    unsigned __int64 ticks = __rdtsc();
    

    See info on that intristic here.

    Both solutions are Windows only, the latter is probably MSVC only. I can post a similar solution for GCC/Linux if needed.

提交回复
热议问题