Loading [MathJax]/jax/input/TeX/config.js
Logo ROOT   6.08/07
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
perfcomp.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 ///
4 /// \macro_code
5 ///
6 /// \date 2015-07-08
7 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
8 /// \author Axel Naumann <axel@cern.ch>
9 
10 /*************************************************************************
11  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
12  * All rights reserved. *
13  * *
14  * For the licensing terms see $ROOTSYS/LICENSE. *
15  * For the list of contributors see $ROOTSYS/README/CREDITS. *
16  *************************************************************************/
17 
18 #include "ROOT/THist.hxx"
19 #include "ROOT/TFit.hxx"
21 
22 #include "TH2.h"
23 
24 #include <chrono>
25 #include <iostream>
26 #include <type_traits>
27 
28 long createNewII(int count) {
29  long ret = 1;
30  for (int i = 0; i < count; ++i) {
31  Experimental::TH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
32  ret ^= (long)&hist;
33  }
34  return ret;
35 }
36 
37 #define BINSOLD \
38  static const int nBinsX = 4; \
39  double x[nBinsX] = {0., 0.1, 0.3, 1.}; \
40  static const int nBinsY = 5; \
41  double y[nBinsY] = {0., 1., 2., 3., 10.}
42 
43 #define DECLOLD \
44  TH2D hist("a", "a hist", nBinsX - 1, x, nBinsY - 1, y)
45 
46 
47 #define OLD \
48  BINSOLD; \
49  DECLOLD
50 
51 long createOldII(int count) {
52  BINSOLD;
53  long ret = 1;
54  for (int i = 0; i < count; ++i) {
55  DECLOLD;
56  ret ^= (long)&hist;
57  }
58  return ret;
59 }
60 
61 long fillNewII(int count) {
62  Experimental::TH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
63  for (int i = 0; i < count; ++i)
64  hist.Fill({0.611, 0.611});
65  return hist.GetNDim();
66 }
67 
68 long fillOldII(int count) {
69  OLD;
70  for (int i = 0; i < count; ++i)
71  hist.Fill(0.611, 0.611);
72  return (long)hist.GetEntries();
73 }
74 
75 long fillNII(int count) {
76  Experimental::TH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
77  std::vector<std::array<double,2>> v(count);
78  for (int i = 0; i < count; ++i)
79  v[i] = {0.611, 0.611};
80  hist.FillN(v);
81  return hist.GetNDim();
82 }
83 
84 long fillBufferedOldII(int count) {
85  OLD;
86  hist.SetBuffer(TH1::GetDefaultBufferSize());
87  for (int i = 0; i < count; ++i)
88  hist.Fill(0.611, 0.611);
89  return (long)hist.GetEntries();
90 }
91 
92 long fillBufferedNewII(int count) {
93  Experimental::TH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
94  Experimental::THistBufferedFill<Experimental::TH2D> filler(hist);
95  for (int i = 0; i < count; ++i)
96  filler.Fill({0.611, 0.611});
97  return hist.GetNDim();
98 }
99 
100 
101 
102 // EQUIDISTANT
103 
104 long createNewEE(int count) {
105  long ret = 1;
106  for (int i = 0; i < count; ++i) {
107  Experimental::TH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
108  ret ^= (long)&hist;
109  }
110  return ret;
111 }
112 
113 long createOldEE(int count) {
114  long ret = 1;
115  for (int i = 0; i < count; ++i) {
116  TH2D hist("a", "a hist", 100, 0., 1., 5, 0., 10.);
117  ret ^= (long)&hist;
118  }
119  return ret;
120 }
121 
122 long fillNewEE(int count) {
123  Experimental::TH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
124  for (int i = 0; i < count; ++i)
125  hist.Fill({0.611, 0.611});
126  return hist.GetNDim();
127 }
128 
129 long fillOldEE(int count) {
130  TH2D hist("a", "a hist", 100, 0., 1., 5, 0., 10.);
131  for (int i = 0; i < count; ++i)
132  hist.Fill(0.611, 0.611);
133  return (long)hist.GetEntries();
134 }
135 
136 long fillNEE(int count) {
137  Experimental::TH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
138  std::vector<std::array<double,2>> v(count);
139  for (int i = 0; i < count; ++i)
140  v[i] = {0.611, 0.611};
141  hist.FillN(v);
142  return hist.GetNDim();
143 }
144 
145 long fillBufferedOldEE(int count) {
146  TH2D hist("a", "a hist", 100, 0., 1., 5, 0., 10.);
147  hist.SetBuffer(TH1::GetDefaultBufferSize());
148  for (int i = 0; i < count; ++i)
149  hist.Fill(0.611, 0.611);
150  return (long)hist.GetEntries();
151 }
152 
153 long fillBufferedNewEE(int count) {
154  Experimental::TH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
155  Experimental::THistBufferedFill<Experimental::TH2D> filler(hist);
156  for (int i = 0; i < count; ++i)
157  filler.Fill({0.611, 0.611});
158  return hist.GetNDim();
159 }
160 
161 
162 using timefunc_t = std::add_pointer_t<long(int)>;
163 
164 void time1(timefunc_t run, int count, const std::string& name) {
165  using namespace std::chrono;
166  auto start = high_resolution_clock::now();
167  run(count);
168  auto end = high_resolution_clock::now();
169  duration<double> time_span = duration_cast<duration<double>>(end - start);
170 
171  std::cout << count << " * " << name << ": " << time_span.count() << "seconds \n";
172 }
173 
174 void time(timefunc_t r6, timefunc_t r7, int count, const std::string& name) {
175  time1(r6, count, name + " (ROOT6)");
176  time1(r7, count, name + " (ROOT7)");
177 }
178 
179 void perfcomp() {
180  int factor = 1000000;
181  //factor = 1; // debug, fast!
182  time(createOldII, createNewII, factor, "create 2D hists [II]");
183  time(createOldEE, createNewEE, factor, "create 2D hists [EE]");
184  time(fillOldII, fillNewII, 100 * factor, "2D fills [II]");
185  time(fillOldEE, fillNewEE, 100 * factor, "2D fills [EE]");
186  time(fillBufferedOldII, fillBufferedNewII, 100 * factor, "2D fills (buffered) [II]");
187  time(fillBufferedOldEE, fillBufferedNewEE, 100 * factor, "2D fills (buffered) [EE]");
188  return 0;
189 }
SVector< double, 2 > v
Definition: Dict.h:5
void run(bool only_compile=false)
Definition: run.C:1
static Int_t GetDefaultBufferSize()
Static function return the default buffer size for automatic histograms the parameter fgBufferSize ma...
Definition: TH1.cxx:4036
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
Definition: THist.hxx:307
char name[80]
Definition: TGX11.cxx:109
tomato 2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:296