Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename Time = std::chrono::microseconds,
- typename Clock = std::chrono::high_resolution_clock>
- struct QuickTimer{
- template<typename F, typename... Args>
- static Time duration(F&& f, Args... args){
- auto start = Clock::now();
- std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
- auto end = Clock::now();
- return std::chrono::duration_cast<Time>(end - start);
- }
- };
- //Usage:
- using namespace std::chrono;
- auto t = QuickTimer<>::duration(myFunction);
- std::cout << duration<double, std::milli>(t).count() << "ms\n";
- std::cout << duration<double, std::nano>(t).count() << "ns\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement