Linux 时间函数的使用
生活随笔
收集整理的這篇文章主要介紹了
Linux 时间函数的使用
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
頭文件
#include <chrono> #include <functional>namespace hsm { namespace common {class Timer { public:Timer();void reset();long peek_us() const;long peek_ms() const;double peek_msf() const;double record_msf(const std::function<void()> &func);private:std::chrono::system_clock::time_point start; };} // namespace common } // namespace hsm對(duì)應(yīng)實(shí)現(xiàn)?
#include "common/timer.h"namespace hsm { namespace common {using namespace std::chrono;Timer::Timer() { reset(); };void Timer::reset() { start = system_clock::now(); }long Timer::peek_us() const {return duration_cast<microseconds>(system_clock::now() - start).count(); }long Timer::peek_ms() const {return duration_cast<milliseconds>(system_clock::now() - start).count(); }double Timer::peek_msf() const { return static_cast<double>(peek_us()) / 1e3; }double Timer::record_msf(const std::function<void()> &func) {reset();func();return peek_msf(); }} // namespace common } // namespace hsm?
總結(jié)
以上是生活随笔為你收集整理的Linux 时间函数的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 桂林银行美团信用卡额度一般是多少?不同额
- 下一篇: 大周期股票是什么意思