TOP > その他
タイマー(Timer)
説明
ある時点からの経過時間を観測する。
計算量
- $O(1)$
実装例
- reset():= タイマーをリセットする。
- elapsed():= リセットしてからの経過時間をミリ秒単位で返す。
struct Timer {
chrono::high_resolution_clock::time_point st;
Timer() { reset(); }
void reset() {
st = chrono::high_resolution_clock::now();
}
chrono::milliseconds::rep elapsed() {
auto ed = chrono::high_resolution_clock::now();
return chrono::duration_cast< chrono::milliseconds >(ed - st).count();
}
};