Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <chrono>
- #include <iostream>
- #include <string>
- #include <string_view>
- class TimerGuard {
- private:
- std::string message_;
- std::ostream &out_;
- using Clock = std::chrono::high_resolution_clock;
- std::chrono::time_point<Clock> start_;
- public:
- TimerGuard(std::string_view message = "",
- std::ostream &out = std::cout) : message_(message),
- out_(out),
- start_(Clock::now()) {
- out_ << "{" << message_ << "}" << " ";
- }
- ~TimerGuard() {
- std::chrono::duration<double> diff = std::chrono::high_resolution_clock::now() - start_;
- out_ << "{" <<
- diff.count() <<
- "}";
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement