用C++测量程序的CPU时间和挂钟时间

fir*_*fly 4 c++

std::clock()测量程序持续时间内的时钟周期数.在以下代码中,它是否计算CPU时间或挂钟时间?

std :: clock_t start; 双倍期;

start = std::clock();

/* Your algorithm here */

duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
Run Code Online (Sandbox Code Playgroud)

在另一种情况下,使用以下代码:

std::clock_t start;
double time;
start = std::clock();
time = start  / (double) CLOCKS_PER_SEC;
Run Code Online (Sandbox Code Playgroud)

时间的价值是多少?

Car*_*rum 6

从文档:

std::clock 时间可以比挂钟更快或更慢地进行,这取决于操作系统给予程序的执行资源.