Created
February 27, 2020 07:26
-
-
Save matthew-d-jones/f2f18da4e6d2c01666974dc57514c746 to your computer and use it in GitHub Desktop.
MATLAB-style tictoc, simple timing functions for C++
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
| #pragma once | |
| #include <chrono> | |
| #include <iostream> | |
| using Clock = std::chrono::high_resolution_clock; | |
| static Clock::time_point t0 = Clock::now(); | |
| void tic() { t0 = Clock::now(); } | |
| void toc() { | |
| Clock::time_point t1 = Clock::now(); | |
| auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0); | |
| auto us = std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0); | |
| std::cout << ms.count() << " ms, " << us.count() << " us\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment