Last active
May 29, 2018 11:03
-
-
Save olzhas/ceeace3bc2903970161028f7cd46d7cd to your computer and use it in GitHub Desktop.
simple tic and toc
This file contains 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 TIMER_H | |
#define TIMER_H | |
#include <chrono> | |
#include <thread> | |
using timer = std::chrono::high_resolution_clock::time_point; | |
inline void tic(timer &t){ | |
t = std::chrono::high_resolution_clock::now(); | |
} | |
inline double toc(const timer &t){ | |
return (std::chrono::high_resolution_clock::now() - t).count()*1e-9; | |
} | |
inline void tic(timer *t){ | |
*t = std::chrono::high_resolution_clock::now(); | |
} | |
inline double toc(const timer *t){ | |
return (std::chrono::high_resolution_clock::now() - *t).count()*1e-9; | |
} | |
inline void Sleep(int msec) | |
{ | |
std::this_thread::sleep_for(std::chrono::milliseconds(msec)); | |
} | |
#endif // TIMER_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The example usage code
for details http://en.cppreference.com/w/cpp/chrono