Logo ROOT   6.10/09
Reference Guide
speedtest.cxx
Go to the documentation of this file.
1 #include "TRandom3.h"
2 #include <vector>
3 #include <chrono>
4 #include <iostream>
5 
6 #include "TH1.h"
7 #include "TH2.h"
8 #include "TH3.h"
9 
10 #include "ROOT/THist.hxx"
12 
13 using namespace ROOT;
14 using namespace std;
15 
16 constexpr unsigned short gRepeat = 2;
17 
18 /* DataTypes:
19 
20  THistDataContent
21  THistDataUncertainty
22  THistDataMomentUncert
23  THistDataRuntime
24 and
25  MyTHistDataNoStat
26  MyTHistDataContent
27  MyTHistDataMomentUncert
28 
29  /opt/build/root_builds/rootcling.cmake/include/ROOT/THistBinIter.h:53:50: error: no member named 'GetUncertainty' in 'ROOT::Experimental::THistDataContent<2, double, ROOT::Experimental::THistDataDefaultStorage>::TBinStat<double>'
30  auto GetUncertainty() const { return GetStat().GetUncertainty(); }
31  ~~~~~~~~~ ^
32 
33  new ones (STATCLASSES)
34 
35  THistStatContent
36  THistStatUncertainty
37  THistStatTotalSumOfWeights
38  THistStatTotalSumOfSquaredWeights
39  THistDataMomentUncert
40 
41 
42  */
43 
44 #ifndef STATCLASSES
45 #define STATCLASSES THistStatContent, THistStatUncertainty
46 #endif
47 
48 
49 struct Timer {
50  using TimePoint_t = decltype( std::chrono::high_resolution_clock::now() );
51 
52  const char *fTitle;
53  size_t fCount;
54  TimePoint_t fStart;
55 
56  Timer(const char *title, size_t count) : fTitle(title), fCount(count),
57  fStart(std::chrono::high_resolution_clock::now()) {}
58 
59  ~Timer() {
60  using namespace std::chrono;
61  auto end = high_resolution_clock::now();
62  duration<double> time_span = duration_cast<duration<double>>(end - fStart);
63  //std::cout << fCount << " * " << fTitle << ": " << time_span.count() << " seconds \n";
64  //std::cout << fCount << " * " << fTitle << ": " << fCount / (1e6) / time_span.count() << " millions per seconds \n";
65  std::cout << fCount << " * " << fTitle << "," << time_span.count() << ",seconds ,";
66  std::cout << fCount / (1e6) / time_span.count() << ",millions per seconds \n";
67  }
68 };
69 
70 constexpr UInt_t gStride = 32; // TH1::GetDefaultBufferSize()
71 
72 struct BinEdges
73 {
74  static constexpr size_t fNBinsX = 4;
75  static constexpr size_t fNBinsY = 5;
76  double fXBins[4];
77  double fYBins[5];
78 
79  BinEdges(double minValue, double maxValue) {
80  if (maxValue < minValue) swap(minValue,maxValue);
81  double range = maxValue - minValue;
82 
83  double x[fNBinsX] = {0., 0.1, 0.3, 1.};
84  double y[fNBinsY] = {0., 0.1, 0.2, 0.3, 1.};
85 
86  for(size_t i = 0; i < fNBinsX; ++i)
87  fXBins[i] = minValue + range * x[i];
88  for(size_t i = 0; i < fNBinsY; ++i)
89  fYBins[i] = minValue + range * y[i];
90 
91  }
92 
93  using AConf_t = Experimental::TAxisConfig;
94 
95  AConf_t GetConfigX() const { return AConf_t(std::array_view<double>(fXBins).to_vector()); }
96  AConf_t GetConfigY() const { return AConf_t(std::array_view<double>(fYBins).to_vector()); }
97 
98 };
99 
100 template <typename T>
101 void GenerateInput(std::vector<T> &numbers, double minVal, double maxVal, UInt_t seed)
102 {
103  Timer t("GenerateInput",numbers.size());
104  if (minVal > maxVal) {
105  std::swap(minVal,maxVal);
106  }
107  T range = maxVal - minVal;
108  TRandom3 r(seed);
109  size_t len = numbers.size();
110  for(auto c = numbers.begin(); c != numbers.end(); ++c) {
111  *c = minVal + range * r.Rndm();
112  }
113 }
114 
115 std::string MakeTitle(std::string_view version,
116  std::string_view histname,
117  std::string_view title,
118  std::string_view axis)
119 {
120  std::string result = std::string(version) + " " + std::string(histname) + " " + title.to_string() + " [" + axis.to_string() + "]";
121  return result;
122 }
123 
124 template <int dim, typename type> const char *GetHist();
125 
126 template <> const char *GetHist<2,double>(){ return "2D"; };
127 template <> const char *GetHist<2,float>() { return "2F"; };
128 
129 template <> const char *GetHist<1,double>(){ return "1D"; };
130 template <> const char *GetHist<1,float>() { return "1F"; };
131 
132 
133 namespace R7 {
134  const char *gVersion = "R7";
135 
136  template <typename T, unsigned short kNDim> struct Dim;
137  using namespace ROOT::Experimental;
138 
139  template <typename T>
140  struct Dim<T,2> {
141 
142  constexpr static unsigned short kNDim = 2;
144 
145  // This is odd ...
146  using InputType_t = double;
147 
148  using FillFunc_t = std::add_pointer_t<long(ExpTH2 &hist, std::vector<InputType_t> &input, std::string_view type)>;
149 
150 
151  struct EE {
152  static constexpr const char * const gType = "regular bin size ";
153 
154  template <FillFunc_t filler>
155  static long Execute(std::vector<InputType_t> &input, double minVal, double maxVal) {
156 
157  long result = 0;
158  for(unsigned short i = 0; i < gRepeat; ++ i) {
159  ExpTH2 hist({100, minVal, maxVal}, {5, minVal, maxVal});
160  result += filler(hist,input,gType);
161  }
162  return result;
163  }
164  };
165 
166  struct II {
167  static constexpr const char * const gType = "irregular bin size";
168 
169  template <FillFunc_t filler>
170  static long Execute(std::vector<InputType_t> &input, double minVal, double maxVal) {
171 
172  long result = 0;
173  BinEdges edges(minVal,maxVal);
174  for(unsigned short i = 0; i < gRepeat; ++ i) {
175  ExpTH2 hist( edges.GetConfigX(), edges.GetConfigY() );
176  result += filler(hist,input,gType);
177  }
178  return result;
179  }
180  };
181 
182  inline static long fillN(ExpTH2 &hist, std::vector<InputType_t> &input, std::string_view gType) {
183 
184  // This is odd :( ...
185  using array_t = std::array<InputType_t, 2>;
186  array_t *values = (array_t*)(&input[0]);
187  constexpr size_t stride = gStride;
188 
189  std::string title = MakeTitle(gVersion, GetHist<kNDim, T>(), "fills N (stride 32)", gType);
190  {
191  Timer t(title.c_str(),input.size()/2);
192  for (size_t i = 0; i < (input.size()-(stride*2-1)); i += (stride*2), values += 32)
193  hist.FillN({values,32});
194  }
195  return hist.GetNDim();
196  }
197 
198 
199  inline static long fillBuffered(ExpTH2 &hist, std::vector<InputType_t> &input, std::string_view gType) {
201  std::string title = MakeTitle(gVersion, GetHist<kNDim, T>(),"fills (buffered) ", gType);
202  {
203  Timer t(title.c_str(),input.size()/2);
204  for (size_t i = 0; i < input.size()-1; i += 2)
205  filler.Fill({input[i], input[i+1]});
206  }
207  return hist.GetNDim();
208  }
209 
210  inline static long fill(ExpTH2 &hist, std::vector<InputType_t> &input, std::string_view gType) {
211  std::string title = MakeTitle(gVersion, GetHist<kNDim, T>(),"fills ", gType);
212  {
213  Timer t(title.c_str(),input.size()/2);
214  for (size_t i = 0; i < input.size()-1; i += 2)
215  hist.Fill({input[i], input[i+1]});
216  }
217  return hist.GetNDim();
218  }
219  }; // DimD
220 
221 
222  template <typename T>
223  struct Dim<T,1> {
224 
225  constexpr static unsigned short kNDim = 1;
227 
228  // This is odd ...
229  using InputType_t = double;
230 
231  using FillFunc_t = std::add_pointer_t<long(ExpTH1 &hist, std::vector<InputType_t> &input, std::string_view type)>;
232 
233 
234  struct EE {
235  static constexpr const char * const gType = "regular bin size ";
236 
237  template <FillFunc_t filler>
238  static long Execute(std::vector<InputType_t> &input, double minVal, double maxVal) {
239 
240  long result = 0;
241  for(unsigned short i = 0; i < gRepeat; ++ i) {
242  ExpTH1 hist({100, minVal, maxVal});
243  result += filler(hist,input,gType);
244  }
245  return result;
246  }
247  };
248 
249  struct II {
250  static constexpr const char * const gType = "irregular bin size";
251 
252  template <FillFunc_t filler>
253  static long Execute(std::vector<InputType_t> &input, double minVal, double maxVal) {
254 
255  long result = 0;
256  BinEdges edges(minVal,maxVal);
257  for(unsigned short i = 0; i < gRepeat; ++ i) {
258  ExpTH1 hist( edges.GetConfigX() );
259  result += filler(hist,input,gType);
260  }
261  return result;
262  }
263  };
264 
265  inline static long fillN(ExpTH1 &hist, std::vector<InputType_t> &input, std::string_view gType) {
266 
267  // This is odd :( ...
268  using array_t = std::array<InputType_t, 1>;
269  array_t *values = (array_t*)(&input[0]);
270  constexpr size_t stride = gStride;
271 
272  std::string title = MakeTitle(gVersion, GetHist<kNDim, T>(), "fills N (stride 32)", gType);
273  {
274  Timer t(title.c_str(),input.size());
275  for (size_t i = 0; i < (input.size()-(stride-1)); i += (stride), values += 32)
276  hist.FillN({values,32});
277  }
278  return hist.GetNDim();
279  }
280 
281 
282  inline static long fillBuffered(ExpTH1 &hist, std::vector<InputType_t> &input, std::string_view gType) {
284  std::string title = MakeTitle(gVersion, GetHist<kNDim, T>(),"fills (buffered) ", gType);
285  {
286  Timer t(title.c_str(),input.size());
287  for (size_t i = 0; i < input.size(); ++i)
288  filler.Fill({input[i]});
289  }
290  return hist.GetNDim();
291  }
292 
293  inline static long fill(ExpTH1 &hist, std::vector<InputType_t> &input, std::string_view gType) {
294  std::string title = MakeTitle(gVersion, GetHist<kNDim, T>(),"fills ", gType);
295  {
296  Timer t(title.c_str(),input.size());
297  for (size_t i = 0; i < input.size(); ++i)
298  hist.Fill({input[i]});
299  }
300  return hist.GetNDim();
301  }
302  }; // Dim1
303 
304 
305 
306 } // R7
307 
308 
309 
310 
311 namespace R6 {
312  const char *gVersion = "R6";
313 
314  template <int ndim, typename T> struct Redirect;
315  template <> struct Redirect<2,float> { using HistType_t = TH2F; };
316  template <> struct Redirect<2,double> { using HistType_t = TH2D; };
317  template <> struct Redirect<1,float> { using HistType_t = TH1F; };
318  template <> struct Redirect<1,double> { using HistType_t = TH1D; };
319 
320  template <typename T, int kNDim> struct Dim;
321 
322  template <typename T>
323  struct Dim<T,2> {
324 
325  constexpr static unsigned short kNDim = 2;
326  using HistType_t = typename Redirect<kNDim,T>::HistType_t;
327 
328  // This is odd ...
329  using InputType_t = double;
330 
331  using FillFunc_t = std::add_pointer_t<long(HistType_t &hist, std::vector<InputType_t> &input, std::string_view type)>;
332 
333 
334  struct EE {
335 
336  static constexpr const char * const gType = "regular bin size ";
337 
338  template <FillFunc_t filler>
339  static long Execute(std::vector<InputType_t> &input, double minVal, double maxVal) {
340 
341  long result = 0;
342  for(unsigned short i = 0; i < gRepeat; ++ i) {
343  HistType_t hist("a", "a hist", 100, minVal, maxVal, 5, minVal, maxVal);
344  result += filler(hist,input,gType);
345  }
346  return result;
347  }
348  };
349 
350  struct II {
351 
352  static constexpr const char * const gType = "irregular bin size";
353 
354  template <FillFunc_t filler>
355  static long Execute(std::vector<InputType_t> &input, double minVal, double maxVal) {
356 
357  long result = 0;
358  BinEdges edges(minVal,maxVal);
359  for(unsigned short i = 0; i < gRepeat; ++ i) {
360  HistType_t hist("a", "a hist", edges.fNBinsX - 1, edges.fXBins, edges.fNBinsY - 1, edges.fYBins);
361  result += filler(hist,input,gType);
362  }
363  return result;
364  }
365  };
366 
367 
368  static long fillBuffered(HistType_t &hist, std::vector<InputType_t> &input, std::string_view gType) {
369  std::string title = MakeTitle(gVersion, GetHist<kNDim,T>(),"fills (buffered) ", gType);
370  hist.SetBuffer(TH1::GetDefaultBufferSize());
371  {
372  //Timer t("R6 2D fills [regular bins size]",input.size()/2);
373  Timer t(title.c_str(),input.size()/2);
374  for (size_t i = 0; i < input.size()-1; i += 2)
375  hist.Fill(input[i], input[i+1]);
376  }
377  return (long)hist.GetEntries();
378  }
379 
380 
381  static long fillN(HistType_t &hist, std::vector<InputType_t> &input, std::string_view gType) {
382  std::string title = MakeTitle(gVersion, GetHist<kNDim,T>(),"fills N (stride 32)", gType);
383  constexpr size_t stride = gStride;
384  {
385  //Timer t("R6 2D fills [regular bins size]",input.size()/2);
386  Timer t(title.c_str(),input.size()/2);
387  for (size_t i = 0; i < (input.size()-(stride*2-1)); i += (stride*2))
388  hist.FillN(gStride, &(input[i]), &(input[i+gStride]), nullptr);
389  }
390  return (long)hist.GetEntries();
391  }
392 
393  static long fill(HistType_t &hist, std::vector<InputType_t> &input, std::string_view gType) {
394  std::string title = MakeTitle(gVersion, GetHist<kNDim,T>(),"fills ", gType);
395  {
396  //Timer t("R6 2D fills [regular bins size]",input.size()/2);
397  Timer t(title.c_str(),input.size()/2);
398  for (size_t i = 0; i < input.size()-1; i += 2)
399  hist.Fill(input[i], input[i+1]);
400  }
401  return (long)hist.GetEntries();
402  }
403  }; // Dim
404 
405  template <typename T>
406  struct Dim<T,1> {
407 
408  constexpr static unsigned short kNDim = 1;
409  using HistType_t = typename Redirect<kNDim,T>::HistType_t;
410 
411  // This is odd ...
412  using InputType_t = double;
413 
414  using FillFunc_t = std::add_pointer_t<long(HistType_t &hist, std::vector<InputType_t> &input, std::string_view type)>;
415 
416 
417  struct EE {
418 
419  static constexpr const char * const gType = "regular bin size ";
420 
421  template <FillFunc_t filler>
422  static long Execute(std::vector<InputType_t> &input, double minVal, double maxVal) {
423 
424  long result = 0;
425  for(unsigned short i = 0; i < gRepeat; ++ i) {
426  HistType_t hist("a", "a hist", 100, minVal, maxVal);
427  result += filler(hist,input,gType);
428  }
429  return result;
430  }
431  };
432 
433  struct II {
434 
435  static constexpr const char * const gType = "irregular bin size";
436 
437  template <FillFunc_t filler>
438  static long Execute(std::vector<InputType_t> &input, double minVal, double maxVal) {
439 
440  long result = 0;
441  BinEdges edges(minVal,maxVal);
442  for(unsigned short i = 0; i < gRepeat; ++ i) {
443  HistType_t hist("a", "a hist", edges.fNBinsX - 1, edges.fXBins);
444  result += filler(hist,input,gType);
445  }
446  return result;
447  }
448  };
449 
450 
451  static long fillBuffered(HistType_t &hist, std::vector<InputType_t> &input, std::string_view gType) {
452  std::string title = MakeTitle(gVersion, GetHist<kNDim,T>(),"fills (buffered) ", gType);
453  hist.SetBuffer(TH1::GetDefaultBufferSize());
454  {
455  //Timer t("R6 2D fills [regular bins size]",input.size()/2);
456  Timer t(title.c_str(),input.size());
457  for (size_t i = 0; i < input.size()-1; ++i)
458  hist.Fill(input[i]);
459  }
460  return (long)hist.GetEntries();
461  }
462 
463 
464  static long fillN(HistType_t &hist, std::vector<InputType_t> &input, std::string_view gType) {
465  std::string title = MakeTitle(gVersion, GetHist<kNDim,T>(),"fills N (stride 32)", gType);
466  constexpr size_t stride = gStride;
467  {
468  //Timer t("R6 2D fills [regular bins size]",input.size()/2);
469  Timer t(title.c_str(),input.size());
470  for (size_t i = 0; i < (input.size()-(stride-1)); i += (stride))
471  hist.FillN(gStride, &(input[i]), nullptr);
472  }
473  return (long)hist.GetEntries();
474  }
475 
476  static long fill(HistType_t &hist, std::vector<InputType_t> &input, std::string_view gType) {
477  std::string title = MakeTitle(gVersion, GetHist<kNDim,T>(),"fills ", gType);
478  {
479  //Timer t("R6 2D fills [regular bins size]",input.size()/2);
480  Timer t(title.c_str(),input.size());
481  for (size_t i = 0; i < input.size(); ++i)
482  hist.Fill(input[i]);
483  }
484  return (long)hist.GetEntries();
485  }
486  }; // Dim1
487 }
488 
489 template <typename T,unsigned short kNDim>
490 void speedtest(size_t count = (size_t)(1e6));
491 
492 template <>
493 void speedtest<double,2>(size_t count) {
494  using DataType_t = double;
495  using InputType_t = double;
496  static constexpr unsigned short kNDim = 2;
497 
499 
500  std::vector<InputType_t> input; // (count);
501  input.resize(count);
502 
503  double minVal = -5.0;
504  double maxVal = +5.0;
505  GenerateInput(input, minVal, maxVal, 0);
506 
507  // Make sure we have some overflow.
508  minVal *= 0.9;
509  maxVal *= 0.9;
510 
511  cout << '\n';
512 
513  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fillBuffered >(input, minVal, maxVal);
514  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
515  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
516 
517  cout << '\n';
518 
519  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
520  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
521  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
522 
523  cout << '\n';
524 
525  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
526  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
527  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
528 
529  cout << '\n';
530 
531  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
532  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
533  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
534 
535  cout << '\n';
536 }
537 
538 
539 // these are copy/paste to work around failure to properly instantiate the template :(
540 
541 template <>
542 void speedtest<float,2>(size_t count) {
543  using DataType_t = float;
544  using InputType_t = double;
545  constexpr unsigned short kNDim = 2;
546 
548 
549  std::vector<InputType_t> input; // (count);
550  input.resize(count);
551 
552  double minVal = -5.0;
553  double maxVal = +5.0;
554  GenerateInput(input, minVal, maxVal, 0);
555 
556  // Make sure we have some overflow.
557  minVal *= 0.9;
558  maxVal *= 0.9;
559 
560  cout << '\n';
561 
562  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fillBuffered >(input, minVal, maxVal);
563  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
564  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
565 
566  cout << '\n';
567 
568  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
569  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
570  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
571 
572  cout << '\n';
573 
574  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
575  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
576  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
577 
578  cout << '\n';
579 
580  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
581  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
582  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
583 
584 }
585 
586 template <>
587 void speedtest<double,1>(size_t count) {
588  using DataType_t = double;
589  using InputType_t = double;
590  static constexpr unsigned short kNDim = 1;
591 
593 
594  std::vector<InputType_t> input; // (count);
595  input.resize(count);
596 
597  double minVal = -5.0;
598  double maxVal = +5.0;
599  GenerateInput(input, minVal, maxVal, 0);
600 
601  // Make sure we have some overflow.
602  minVal *= 0.9;
603  maxVal *= 0.9;
604 
605  cout << '\n';
606 
607  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fillBuffered >(input, minVal, maxVal);
608  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
609  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
610 
611  cout << '\n';
612 
613  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
614  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
615  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
616 
617  cout << '\n';
618 
619  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
620  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
621  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
622 
623  cout << '\n';
624 
625  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
626  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
627  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
628 
629 }
630 
631 template <>
632 void speedtest<float,1>(size_t count) {
633  using DataType_t = float;
634  using InputType_t = double;
635  static constexpr unsigned short kNDim = 1;
636 
638 
639  std::vector<InputType_t> input; // (count);
640  input.resize(count);
641 
642  double minVal = -5.0;
643  double maxVal = +5.0;
644  GenerateInput(input, minVal, maxVal, 0);
645 
646  // Make sure we have some overflow.
647  minVal *= 0.9;
648  maxVal *= 0.9;
649 
650  cout << '\n';
651 
652  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fillBuffered >(input, minVal, maxVal);
653  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
654  R7::Dim<DataType_t,kNDim>::EE::Execute<R7::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
655 
656  cout << '\n';
657 
658  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
659  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
660  R7::Dim<DataType_t,kNDim>::II::Execute<R7::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
661 
662  cout << '\n';
663 
664  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
665  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
666  R6::Dim<DataType_t,kNDim>::EE::Execute<R6::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
667 
668  cout << '\n';
669 
670  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fillBuffered>(input, minVal, maxVal);
671  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fillN>(input, minVal, maxVal);
672  R6::Dim<DataType_t,kNDim>::II::Execute<R6::Dim<DataType_t,kNDim>::fill>(input, minVal, maxVal);
673 
674 }
675 
676 void histspeedtest(size_t iter, int what) {
677 
678  if (what & 1) speedtest<double,2>(iter);
679  if (what & 2) speedtest<float,2>(iter);
680  if (what & 4) speedtest<double,1>(iter);
681  if (what & 8) speedtest<float,1>(iter);
682 
683 }
684 
685 int main(int argc, char **argv) {
686 
687  size_t iter = 1e9;
688  int what = 1|2|4|8;
689  if (argc > 1) iter = atof(argv[1]);
690  if (argc > 2) what = atoi(argv[2]);
691 
692  histspeedtest(iter, what);
693 }
void speedtest< float, 1 >(size_t count)
Definition: speedtest.cxx:632
Random number generator class based on M.
Definition: TRandom3.h:27
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom3.cxx:94
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
double T(double x)
Definition: ChebyshevPol.h:34
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:311
void GenerateInput(std::vector< T > &numbers, double minVal, double maxVal, UInt_t seed)
Definition: speedtest.cxx:101
fill
Definition: fit1_py.py:6
constexpr unsigned short gRepeat
Definition: speedtest.cxx:16
const char * GetHist< 2, double >()
Definition: speedtest.cxx:126
STL namespace.
const char * GetHist< 1, float >()
Definition: speedtest.cxx:130
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition: TH1.cxx:1218
Double_t x[n]
Definition: legend1.C:17
void speedtest< float, 2 >(size_t count)
Definition: speedtest.cxx:542
const char * GetHist< 2, float >()
Definition: speedtest.cxx:127
constexpr UInt_t gStride
Definition: speedtest.cxx:70
const char * GetHist< 1, double >()
Definition: speedtest.cxx:129
Objects used to configure the different axis types.
Definition: TAxis.hxx:311
RooCmdArg Timer(Bool_t flag=kTRUE)
TRandom2 r(17)
static int gType
Definition: proofexecv.cxx:47
unsigned int UInt_t
Definition: RtypesCore.h:42
void speedtest< double, 2 >(size_t count)
Definition: speedtest.cxx:493
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
Definition: THist.hxx:33
static Int_t GetDefaultBufferSize()
Static function return the default buffer size for automatic histograms the parameter fgBufferSize ma...
Definition: TH1.cxx:4037
const Bool_t kFALSE
Definition: RtypesCore.h:92
void speedtest(size_t count=(size_t)(1e6))
const char * GetHist()
int type
Definition: TGX11.cxx:120
Double_t y[n]
Definition: legend1.C:17
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
Definition: THist.hxx:316
std::string MakeTitle(std::string_view version, std::string_view histname, std::string_view title, std::string_view axis)
Definition: speedtest.cxx:115
void speedtest< double, 1 >(size_t count)
Definition: speedtest.cxx:587
void histspeedtest(size_t iter, int what)
Definition: speedtest.cxx:676
const char * gVersion
Definition: speedtest.cxx:312
int main(int argc, char **argv)
Definition: speedtest.cxx:685
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
Definition: THist.hxx:310
double result[121]
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:317