Created
May 21, 2017 02:32
-
-
Save jniemann66/2b9de8dfff2b968b618ccd93b3f52a75 to your computer and use it in GitHub Desktop.
Really simple RAII millisecond timer
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
| #ifndef _RAIITIMER_H | |
| #define _RAIITIMER_H 1 | |
| #include <iostream> | |
| #include <chrono> | |
| class RaiiTimer { | |
| public: | |
| RaiiTimer() { | |
| beginTimer = std::chrono::high_resolution_clock::now(); | |
| } | |
| ~RaiiTimer() { | |
| endTimer = std::chrono::high_resolution_clock::now(); | |
| auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTimer - beginTimer).count(); | |
| std::cout << "Time=" << duration << " ms" << std::endl; | |
| } | |
| private: | |
| std::chrono::time_point<std::chrono::high_resolution_clock> beginTimer; | |
| std::chrono::time_point<std::chrono::high_resolution_clock> endTimer; | |
| }; | |
| #endif // _RAIITIMER_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment