57 PROF_TIMER(
const std::string& aName,
bool aAutostart =
true ) :
105 void Show( std::ostream& aStream = std::cerr )
107 using DURATION = std::chrono::duration<double, std::nano>;
109 const auto duration = SinceStart<DURATION>();
110 const double cnt = duration.count();
114 aStream <<
m_name <<
" took ";
118 aStream << cnt <<
"ns";
120 aStream << ( cnt / 1e3 ) <<
"µs";
122 aStream << ( cnt / 1e6 ) <<
"ms";
124 aStream << ( cnt / 1e9 ) <<
"s";
126 aStream << std::endl;
134 template <
typename DURATION>
142 return std::chrono::duration_cast<DURATION>( stoptime - starttime );
149 double msecs(
bool aSinceLast =
false )
151 using DUR_MS = std::chrono::duration<double, std::milli>;
152 return SinceStart<DUR_MS>( aSinceLast ).count();
157 using DURATION = std::chrono::duration<double, std::nano>;
159 const auto duration = SinceStart<DURATION>();
160 const double cnt = duration.count();
166 std::stringstream time;
171 time << ( cnt / 1e3 ) <<
"µs";
173 time << ( cnt / 1e6 ) <<
"ms";
175 time << ( cnt / 1e9 ) <<
"s";
186 using CLOCK = std::chrono::high_resolution_clock;
211template <
typename DURATION>
277 void Show( std::ostream& aStream = std::cerr )
280 aStream <<
m_name <<
": ";
283 aStream << std::endl;
A thread-safe event counter.
unsigned long long operator++(int)
PROF_COUNTER(const std::string &aName)
unsigned long long Count() const
void Show(std::ostream &aStream=std::cerr)
std::atomic_ullong m_count
A small class to help profiling.
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
std::chrono::high_resolution_clock CLOCK
DURATION SinceStart(bool aSinceLast=false)
void Start()
Start or restart the counter.
PROF_TIMER()
Create a PROF_COUNTER for measuring an elapsed time in milliseconds.
std::chrono::time_point< CLOCK > TIME_POINT
PROF_TIMER(const std::string &aName, bool aAutostart=true)
Create a PROF_COUNTER for measuring an elapsed time in milliseconds.
double msecs(bool aSinceLast=false)
A simple RAII class to measure the time of an operation.
SCOPED_PROF_TIMER(DURATION &aDuration)
PROF_TIMER m_counter
< The counter to use to do the profiling
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.