Skip to content

Instantly share code, notes, and snippets.

@dnbaker
Last active October 21, 2017 17:27
Show Gist options
  • Save dnbaker/d23a443c000cc6511a52f663af2e92d1 to your computer and use it in GitHub Desktop.
Save dnbaker/d23a443c000cc6511a52f663af2e92d1 to your computer and use it in GitHub Desktop.
Code Timing Macro (C++)
// You must have #included <chrono> and <cstdio>
#define TIME_CODE(code, name) do \
{ \
using namespace std::chrono; \
const auto i(system_clock::now()); \
{ code } \
const auto j(system_clock::now()); \
std::fprintf(stderr, "Task %s took %lfs\n", name, duration<double>(j - i).count());\
} while(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment