私は次のようなことを考えていました:
// 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()
しました。chronotime()
を使用せずに、これを達成するためのより良い方法があるかどうかを知りたいです。