Belle II Software development
TimeItResult Class Reference

Class to capture the time a repeated execution took. More...

#include <TimeIt.h>

Public Member Functions

 TimeItResult (const std::vector< std::chrono::duration< double > > &timeSpans)
 Constructor from a series of timings.
 
double getSeconds (size_t iExecution) const
 Get the time of the individual executtions.
 
double getAverageSeconds () const
 Get the average execution time.
 
size_t getNExecutions () const
 Get number of executions.
 
void printSummary () const
 Print a summary of the collected time to the console.
 

Private Attributes

std::vector< std::chrono::duration< double > > m_timeSpans
 Memory for the time spans a repeated execution took.
 

Detailed Description

Class to capture the time a repeated execution took.

Definition at line 29 of file TimeIt.h.

Constructor & Destructor Documentation

◆ TimeItResult()

TimeItResult ( const std::vector< std::chrono::duration< double > > &  timeSpans)
inlineexplicit

Constructor from a series of timings.

Definition at line 32 of file TimeIt.h.

32 :
33 m_timeSpans(timeSpans)
34 {}
std::vector< std::chrono::duration< double > > m_timeSpans
Memory for the time spans a repeated execution took.
Definition: TimeIt.h:66

Member Function Documentation

◆ getAverageSeconds()

double getAverageSeconds ( ) const
inline

Get the average execution time.

Definition at line 43 of file TimeIt.h.

44 {
45 std::chrono::duration<double> sumTimeSpan =
46 std::accumulate(m_timeSpans.begin(), m_timeSpans.end(), std::chrono::duration<double>());
47
48 std::chrono::duration<double> avgTimeSpan = sumTimeSpan / m_timeSpans.size();
49 return avgTimeSpan.count();
50 }

◆ getNExecutions()

size_t getNExecutions ( ) const
inline

Get number of executions.

Definition at line 53 of file TimeIt.h.

54 { return m_timeSpans.size(); }

◆ getSeconds()

double getSeconds ( size_t  iExecution) const
inline

Get the time of the individual executtions.

Definition at line 37 of file TimeIt.h.

38 {
39 return m_timeSpans.at(iExecution).count();
40 }

◆ printSummary()

void printSummary ( ) const
inline

Print a summary of the collected time to the console.

Definition at line 57 of file TimeIt.h.

58 {
59 B2INFO("First execution took " << getSeconds(0) << " seconds ");
60 B2INFO("On average execution took " << getAverageSeconds() << " seconds " <<
61 "in " << getNExecutions() << " executions.");
62 }
size_t getNExecutions() const
Get number of executions.
Definition: TimeIt.h:53
double getSeconds(size_t iExecution) const
Get the time of the individual executtions.
Definition: TimeIt.h:37
double getAverageSeconds() const
Get the average execution time.
Definition: TimeIt.h:43

Member Data Documentation

◆ m_timeSpans

std::vector<std::chrono::duration<double> > m_timeSpans
private

Memory for the time spans a repeated execution took.

Definition at line 66 of file TimeIt.h.


The documentation for this class was generated from the following file: