0
我想的是一样的东西:C++:运行一个量的算法的时间(不计时)
// Runs algorithm() n times during an amount of seconds.
void run(int seconds) {
clock_t start = clock();
clock_t current = start;
while(double (current - start)/CLOCKS_PER_SEC <= seconds) {
algorithm();
current = clock();
}
}
我选择了clock()
到time()
避免会计时间进程睡眠。 我想知道是否有更好的方法来实现这一点,而不使用chrono。
您可以使用更高精度的特定于平台的工具,例如QueryPerformanceCounter,或者使用[Boost's Timers]进行实验(http://www.boost.org/doc/libs/1_51_0/libs/timer/doc/) index.html),但我不知道底层实现是否更好。 – chris
您是否想要便携式解决方案或平台特定的解决方案? –
为什么有人想避免'std :: chrono'? – bames53