Celero
UserDefinedMeasurementTemplate.h
1 #pragma once
2 
20 
21 #include <celero/Statistics.h>
22 #include <celero/UserDefinedMeasurement.h>
23 
24 #include <numeric>
25 #include <type_traits>
26 
27 namespace celero
28 {
36  template <typename T>
38  {
39  static_assert(std::is_arithmetic<T>::value, "UserDefinedMeasurementTemplate requres an arithmetic type.");
40 
41  public:
46 
50  virtual ~UserDefinedMeasurementTemplate() = default;
51 
56  {
57  UDMAggregationTable table;
58 
59  if(this->reportSize() == true)
60  {
61  table.push_back({"# Samp", [this]() { return static_cast<double>(this->getStatistics().getSize()); }});
62  }
63 
64  if(this->reportMean() == true)
65  {
66  table.push_back({"Mean", [this]() { return this->getStatistics().getMean(); }});
67  }
68 
69  if(this->reportVariance() == true)
70  {
71  table.push_back({"Var", [this]() { return this->getStatistics().getVariance(); }});
72  }
73 
74  if(this->reportStandardDeviation() == true)
75  {
76  table.push_back({"StdDev", [this]() { return this->getStatistics().getStandardDeviation(); }});
77  }
78 
79  if(this->reportSkewness() == true)
80  {
81  table.push_back({"Skew", [this]() { return this->getStatistics().getSkewness(); }});
82  }
83 
84  if(this->reportKurtosis() == true)
85  {
86  table.push_back({"Kurtosis", [this]() { return this->getStatistics().getKurtosis(); }});
87  }
88 
89  if(this->reportZScore() == true)
90  {
91  table.push_back({"ZScore", [this]() { return this->getStatistics().getZScore(); }});
92  }
93 
94  if(this->reportMin() == true)
95  {
96  table.push_back({"Min", [this]() { return static_cast<double>(this->getStatistics().getMin()); }});
97  }
98 
99  if(this->reportMax() == true)
100  {
101  table.push_back({"Max", [this]() { return static_cast<double>(this->getStatistics().getMax()); }});
102  }
103 
104  return table;
105  }
106 
110  void addValue(T x)
111  {
112  this->stats.addSample(x);
113  }
114 
118  void merge(const UserDefinedMeasurement* const x) override
119  {
120  const auto toMerge = dynamic_cast<const UserDefinedMeasurementTemplate<T>* const>(x);
121  this->stats += toMerge->stats;
122  }
123 
124  protected:
125  virtual bool reportSize() const
126  {
127  return true;
128  }
129 
130  virtual bool reportMean() const
131  {
132  return true;
133  }
134 
135  virtual bool reportVariance() const
136  {
137  return true;
138  }
139 
140  virtual bool reportStandardDeviation() const
141  {
142  return true;
143  }
144 
145  virtual bool reportSkewness() const
146  {
147  return true;
148  }
149 
150  virtual bool reportKurtosis() const
151  {
152  return true;
153  }
154 
155  virtual bool reportZScore() const
156  {
157  return true;
158  }
159 
160  virtual bool reportMin() const
161  {
162  return true;
163  }
164 
165  virtual bool reportMax() const
166  {
167  return true;
168  }
169 
170  const Statistics<T>& getStatistics() const
171  {
172  return this->stats;
173  }
174 
175  private:
177  Statistics<T> stats;
178  };
179 
180 } // namespace celero
181 
UserDefinedMeasurementTemplate()=default
Default constructor.
Definition: Archive.h:25
std::vector< std::pair< std::string, std::function< double(void)> >> UDMAggregationTable
Describes, which aggregations should be computed on a user-defined measurement.
Definition: UserDefinedMeasurement.h:39
Base class that the user must derive user-defined measurements from.
Definition: UserDefinedMeasurement.h:48
UDMAggregationTable getAggregationInfo() const override
Must be implemented by the user.
Definition: UserDefinedMeasurementTemplate.h:55
Definition: Statistics.h:40
void addValue(T x)
You must call this method from your fixture to add a measurement.
Definition: UserDefinedMeasurementTemplate.h:110
Base class that the user must derive user-defined measurements from.
Definition: UserDefinedMeasurementTemplate.h:37
virtual ~UserDefinedMeasurementTemplate()=default
Default destructor.
void merge(const UserDefinedMeasurement *const x) override
Preserve measurements within a group/experiment/problem space set.
Definition: UserDefinedMeasurementTemplate.h:118