我在想类似的东西:
// 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。