Last active
January 31, 2022 17:06
-
-
Save patrislav1/41d099058033d48d25fd9843e3278b52 to your computer and use it in GitHub Desktop.
miniprofiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <chrono> | |
#include <string> | |
#include <boost/log/core.hpp> | |
#include <boost/log/trivial.hpp> | |
namespace blg = boost::log::trivial; | |
namespace ch = std::chrono; | |
class MiniProf { | |
ch::steady_clock::time_point _start; | |
ch::steady_clock::time_point _end; | |
const std::string _name; | |
public: | |
MiniProf(std::string name) : _name(name){}; | |
void start() { _start = ch::steady_clock::now(); } | |
void stop() { _end = ch::steady_clock::now(); } | |
void log() { | |
auto num_us = ch::duration_cast<ch::microseconds>(_end - _start).count(); | |
BOOST_LOG_TRIVIAL(info) << "Duration '" << _name << "': " << (num_us / 1000) | |
<< "." << (num_us % 1000) << "ms"; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment