performance - Getting an accurate execution time in C++ (micro seconds) -


I want to get an accurate execution time in the mini-seconds of my program implemented with C ++. I have tried to get the execution time with clock_t but this is not correct.

If you are using c ++ 11 or later, then you std :: Chrono can use:: high_resolution_clock .

A simple use case:

  auto start = std :: chrono :: high_resolution_clock :: now (); ... Automatically expired = std :: chrono :: high_resolution_clock :: now () - get started; Long-term microsoft = std :: chrono :: duration_cast & lt; Std :: chrono :: microseconds & gt; (Passed). Count ();  

This solution has the advantage of being portable.


Comments