2023 09 08 15 58 在linux arm64去拿到精準比較高的時間來測量程式所用的時間


在網路上找老半天,找到用這個大概可以使用.
但還是沒有x86/x86_64所用的rdtsc的精度高.

#include <time.h>
inline uint64_t rdtsc(void)
{
        struct timespec tv;
        clock_gettime(CLOCK_MONOTONIC,&tv);
        return ((tv.tv_sec) * 1000000000 + tv.tv_nsec);
}

另外還有用
asm volatile("mrs %0, cntvct_el0" : "=r" (val));
另外還有參考資料
REF: https://github.com/google/benchmark/blob/v1.1.0/src/cycleclock.h