相关疑难解决方法(0)

85
推荐指数
5
解决办法
23万
查看次数

如何在Linux中创建高分辨率计时器来衡量程序性能?

我正在尝试将GPU与CPU性能进行比较.对于NVIDIA GPU,我一直在使用这些cudaEvent_t类型来获得非常精确的时序.

对于CPU我一直在使用以下代码:

// Timers
clock_t start, stop;
float elapsedTime = 0;

// Capture the start time

start = clock();

// Do something here
.......

// Capture the stop time
stop = clock();
// Retrieve time elapsed in milliseconds
elapsedTime = (float)(stop - start) / (float)CLOCKS_PER_SEC * 1000.0f;
Run Code Online (Sandbox Code Playgroud)

显然,如果你在几秒钟内计算,那段代码就是好的.此外,结果有时候出来很奇怪.

有谁知道在Linux中创建高分辨率计时器的某种方法?

c linux precision timer high-resolution

33
推荐指数
2
解决办法
7万
查看次数

标签 统计

c ×2

linux ×2

high-resolution ×1

posix ×1

precision ×1

timer ×1