Created
July 17, 2014 14:42
-
-
Save alexeiz/3ebda630e97c9fb70f1a to your computer and use it in GitHub Desktop.
A simple macro to time execution of a block of code.
This file contains hidden or 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
| #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