Skip to content

Instantly share code, notes, and snippets.

@xylcbd
Last active June 29, 2018 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xylcbd/70a1bc19bfbdab2c2019423674f68b13 to your computer and use it in GitHub Desktop.
Save xylcbd/70a1bc19bfbdab2c2019423674f68b13 to your computer and use it in GitHub Desktop.
#include <chrono>
#include <string>
#include <iostream>
struct profiler
{
std::string name;
std::chrono::high_resolution_clock::time_point p;
profiler(std::string const &n) :
name(n), p(std::chrono::high_resolution_clock::now()) { }
~profiler()
{
using dura = std::chrono::duration<double>;
auto d = std::chrono::high_resolution_clock::now() - p;
std::cout << name << ": "
<< std::chrono::duration_cast<dura>(d).count() * 1000.0 << "ms"
<< std::endl;
}
};
#define PROFILE_BLOCK(pbn) profiler _pfinstance(pbn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment