Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
perfcomp.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_exp
3///
4/// \macro_code
5///
6/// \date 2015-07-08
7/// \warning This is part of the experimental API, which might change in the future. 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/RHist.hxx"
19#include "ROOT/RFit.hxx"
21
22#include "TH2.h"
23
24#include <chrono>
25#include <iostream>
26#include <type_traits>
27
28using namespace ROOT::Experimental;
29
30long createNewII(int count)
31{
32 long ret = 1;
33 for (int i = 0; i < count; ++i) {
34 RH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
35 ret ^= (long)&hist;
36 }
37 return ret;
38}
39
40#define BINSOLD \
41 static const int nBinsX = 4; \
42 double x[nBinsX] = {0., 0.1, 0.3, 1.}; \
43 static const int nBinsY = 5; \
44 double y[nBinsY] = {0., 1., 2., 3., 10.}
45
46#define DECLOLD TH2D hist("a", "a hist", nBinsX - 1, x, nBinsY - 1, y)
47
48#define OLD \
49 BINSOLD; \
50 DECLOLD
51
52long createOldII(int count)
53{
54 BINSOLD;
55 long ret = 1;
56 for (int i = 0; i < count; ++i) {
57 DECLOLD;
58 ret ^= (long)&hist;
59 }
60 return ret;
61}
62
63long fillNewII(int count)
64{
65 RH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
66 for (int i = 0; i < count; ++i)
67 hist.Fill({0.611, 0.611});
68 return hist.GetNDim();
69}
70
71long fillOldII(int count)
72{
73 OLD;
74 for (int i = 0; i < count; ++i)
75 hist.Fill(0.611, 0.611);
76 return (long)hist.GetEntries();
77}
78
79long fillNII(int count)
80{
81 RH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
82 std::vector<Hist::RCoordArray<2>> v(count);
83 for (int i = 0; i < count; ++i)
84 v[i] = {0.611, 0.611};
85 hist.FillN(v);
86 return hist.GetNDim();
87}
88
89long fillBufferedOldII(int count)
90{
91 OLD;
92 hist.SetBuffer(TH1::GetDefaultBufferSize());
93 for (int i = 0; i < count; ++i)
94 hist.Fill(0.611, 0.611);
95 return (long)hist.GetEntries();
96}
97
98long fillBufferedNewII(int count)
99{
100 RH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
101 RHistBufferedFill<RH2D> filler(hist);
102 for (int i = 0; i < count; ++i)
103 filler.Fill({0.611, 0.611});
104 return hist.GetNDim();
105}
106
107// EQUIDISTANT
108
109long createNewEE(int count)
110{
111 long ret = 1;
112 for (int i = 0; i < count; ++i) {
113 RH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
114 ret ^= (long)&hist;
115 }
116 return ret;
117}
118
119long createOldEE(int count)
120{
121 long ret = 1;
122 for (int i = 0; i < count; ++i) {
123 TH2D hist("a", "a hist", 100, 0., 1., 5, 0., 10.);
124 ret ^= (long)&hist;
125 }
126 return ret;
127}
128
129long fillNewEE(int count)
130{
131 RH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
132 for (int i = 0; i < count; ++i)
133 hist.Fill({0.611, 0.611});
134 return hist.GetNDim();
135}
136
137long fillOldEE(int count)
138{
139 TH2D hist("a", "a hist", 100, 0., 1., 5, 0., 10.);
140 for (int i = 0; i < count; ++i)
141 hist.Fill(0.611, 0.611);
142 return (long)hist.GetEntries();
143}
144
145long fillNEE(int count)
146{
147 RH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
148 std::vector<Hist::RCoordArray<2>> v(count);
149 for (int i = 0; i < count; ++i)
150 v[i] = {0.611, 0.611};
151 hist.FillN(v);
152 return hist.GetNDim();
153}
154
155long fillBufferedOldEE(int count)
156{
157 TH2D hist("a", "a hist", 100, 0., 1., 5, 0., 10.);
158 hist.SetBuffer(TH1::GetDefaultBufferSize());
159 for (int i = 0; i < count; ++i)
160 hist.Fill(0.611, 0.611);
161 return (long)hist.GetEntries();
162}
163
164long fillBufferedNewEE(int count)
165{
166 RH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
167 RHistBufferedFill<RH2D> filler(hist);
168 for (int i = 0; i < count; ++i)
169 filler.Fill({0.611, 0.611});
170 return hist.GetNDim();
171}
172
173using timefunc_t = std::add_pointer_t<long(int)>;
174
175void time1(timefunc_t run, int count, const std::string &name)
176{
177 using namespace std::chrono;
178 auto start = high_resolution_clock::now();
179 run(count);
180 auto end = high_resolution_clock::now();
181 duration<double> time_span = duration_cast<duration<double>>(end - start);
182
183 std::cout << count << " * " << name << ": " << time_span.count() << "seconds \n";
184}
185
186void time(timefunc_t r6, timefunc_t r7, int count, const std::string &name)
187{
188 time1(r6, count, name + " (ROOT6)");
189 time1(r7, count, name + " (ROOT7)");
190}
191
192void perfcomp()
193{
194 int factor = 1000000;
195 // factor = 1; // debug, fast!
196 time(createOldII, createNewII, factor, "create 2D hists [II]");
197 time(createOldEE, createNewEE, factor, "create 2D hists [EE]");
198 time(fillOldII, fillNewII, 100 * factor, "2D fills [II]");
199 time(fillOldEE, fillNewEE, 100 * factor, "2D fills [EE]");
200 time(fillBufferedOldII, fillBufferedNewII, 100 * factor, "2D fills (buffered) [II]");
201 time(fillBufferedOldEE, fillBufferedNewEE, 100 * factor, "2D fills (buffered) [EE]");
202}
char name[80]
Definition TGX11.cxx:110
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
Definition RHist.hxx:53
void Fill(const CoordArray_t &x, Weight_t weight=(Weight_t) 1) noexcept
Add weight to the bin containing coordinate x.
Definition RHist.hxx:140
static Int_t GetDefaultBufferSize()
Static function return the default buffer size for automatic histograms the parameter fgBufferSize ma...
Definition TH1.cxx:4401
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:358