用到获取系统时间(纳秒)的函数getTimeNs()

包含头文件:ctime(c++)/time.h(c)

#include<ctime>
long getTimeNs()
{
    struct timespec ts;
    clock_gettime(CLOCK_REALTIME,&ts);

    return ts.tv_sec*1000000000+ts.tv_nsec;
}	

只需要在需要测试时间的代码块前后用调用getTimeNs(),用两个变量接收返回值,相减就是纳秒级的运行时间。(●ˇ∀ˇ●)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2021-05-20
  • 2021-10-23
  • 2022-12-23
  • 2021-07-24
猜你喜欢
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-06-18
  • 2021-06-15
相关资源
相似解决方案