相关疑难解决方法(0)

定时器功能使用C++以纳秒为单位提供时间

我希望计算API返回值所花费的时间.这种行动所花费的时间是纳秒秒.由于API是C++类/函数,我使用timer.h来计算相同的:

  #include <ctime>
  #include <cstdio>

  using namespace std;

  int main(int argc, char** argv) {

      clock_t start;
      double diff;
      start = clock();
      diff = ( std::clock() - start ) / (double)CLOCKS_PER_SEC;
      cout<<"printf: "<< diff <<'\n';

      return 0;
  }
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了以秒为单位的时间.如何在毫秒秒内获得相同的精度?

c c++ timer

101
推荐指数
8
解决办法
20万
查看次数

C++的时差

有谁知道如何用毫秒计算C++的时差?我曾经使用difftime但它没有足够的精度来衡量我正在测量的东西.

c++ time

31
推荐指数
4
解决办法
5万
查看次数

标签 统计

c++ ×2

c ×1

time ×1

timer ×1