Skip to content

Instantly share code, notes, and snippets.

@luoyetx
Last active February 28, 2023 10:37
Show Gist options
  • Save luoyetx/c756327a67378d39ecd2fb8d35da3f5d to your computer and use it in GitHub Desktop.
Save luoyetx/c756327a67378d39ecd2fb8d35da3f5d to your computer and use it in GitHub Desktop.
macros for time evaluation
#include <chrono>
/*! \brief Timer */
class Timer {
using Clock = std::chrono::high_resolution_clock;
public:
/*! \brief start or restart timer */
inline void Tic() {
start_ = Clock::now();
}
/*! \brief stop timer */
inline void Toc() {
end_ = Clock::now();
}
/*! \brief return time in ms */
inline double Elasped() {
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_ - start_);
return duration.count();
}
private:
Clock::time_point start_, end_;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment