Skip to content

Instantly share code, notes, and snippets.

@patrislav1
Last active January 31, 2022 17:06
Show Gist options
  • Save patrislav1/41d099058033d48d25fd9843e3278b52 to your computer and use it in GitHub Desktop.
Save patrislav1/41d099058033d48d25fd9843e3278b52 to your computer and use it in GitHub Desktop.
miniprofiler
#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