Skip to content

Instantly share code, notes, and snippets.

@alexeiz
Created July 17, 2014 14:42
Show Gist options
  • Save alexeiz/3ebda630e97c9fb70f1a to your computer and use it in GitHub Desktop.
Save alexeiz/3ebda630e97c9fb70f1a to your computer and use it in GitHub Desktop.
A simple macro to time execution of a block of code.
#include <boost/timer/timer.hpp>
struct timeit_obj
{
template <typename F>
auto operator+(F && func) -> decltype(func()) const
{
boost::timer::auto_cpu_timer t;
return func();
}
};
#define timeit \
timeit_obj() + [&]
int main(int argc, char * argv[])
{
char const * cmd = "ls";
if (argc > 1)
cmd = argv[1];
auto err = timeit { return system(cmd); };
return err;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment