Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
8/// is welcome!
9/// \author Axel Naumann <axel@cern.ch>
10
11/*************************************************************************
12 * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
13 * All rights reserved. *
14 * *
15 * For the licensing terms see $ROOTSYS/LICENSE. *
16 * For the list of contributors see $ROOTSYS/README/CREDITS. *
17 *************************************************************************/
18
19#include "ROOT/RHist.hxx"
20#include "ROOT/RFit.hxx"
22
23#include "TH2.h"
24
25#include <chrono>
26#include <iostream>
27#include <type_traits>
28
29using namespace ROOT::Experimental;
30
31long createNewII(int count)
32{
33 long ret = 1;
34 for (int i = 0; i < count; ++i) {
35 RH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
36 ret ^= (long)&hist;
37 }
38 return ret;
39}
40
41#define BINSOLD \
42 static const int nBinsX = 4; \
43 double x[nBinsX] = {0., 0.1, 0.3, 1.}; \
44 static const int nBinsY = 5; \
45 double y[nBinsY] = {0., 1., 2., 3., 10.}
46
47#define DECLOLD TH2D hist("a", "a hist", nBinsX - 1, x, nBinsY - 1, y)
48
49#define OLD \
50 BINSOLD; \
51 DECLOLD
52
53long createOldII(int count)
54{
55 BINSOLD;
56 long ret = 1;
57 for (int i = 0; i < count; ++i) {
58 DECLOLD;
59 ret ^= (long)&hist;
60 }
61 return ret;
62}
63
64long fillNewII(int count)
65{
66 RH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
67 for (int i = 0; i < count; ++i)
68 hist.Fill({0.611, 0.611});
69 return hist.GetNDim();
70}
71
72long fillOldII(int count)
73{
74 OLD;
75 for (int i = 0; i < count; ++i)
76 hist.Fill(0.611, 0.611);
77 return (long)hist.GetEntries();
78}
79
80long fillNII(int count)
81{
82 RH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
83 std::vector<Hist::RCoordArray<2>> v(count);
84 for (int i = 0; i < count; ++i)
85 v[i] = {0.611, 0.611};
86 hist.FillN(v);
87 return hist.GetNDim();
88}
89
90long fillBufferedOldII(int count)
91{
92 OLD;
93 hist.SetBuffer(TH1::GetDefaultBufferSize());
94 for (int i = 0; i < count; ++i)
95 hist.Fill(0.611, 0.611);
96 return (long)hist.GetEntries();
97}
98
99long fillBufferedNewII(int count)
100{
101 RH2D hist({{{{0., 0.1, 0.3, 1.}}, {{0., 1., 2., 3., 10.}}}});
102 RHistBufferedFill<RH2D> filler(hist);
103 for (int i = 0; i < count; ++i)
104 filler.Fill({0.611, 0.611});
105 return hist.GetNDim();
106}
107
108// EQUIDISTANT
109
110long createNewEE(int count)
111{
112 long ret = 1;
113 for (int i = 0; i < count; ++i) {
114 RH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
115 ret ^= (long)&hist;
116 }
117 return ret;
118}
119
120long createOldEE(int count)
121{
122 long ret = 1;
123 for (int i = 0; i < count; ++i) {
124 TH2D hist("a", "a hist", 100, 0., 1., 5, 0., 10.);
125 ret ^= (long)&hist;
126 }
127 return ret;
128}
129
130long fillNewEE(int count)
131{
132 RH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
133 for (int i = 0; i < count; ++i)
134 hist.Fill({0.611, 0.611});
135 return hist.GetNDim();
136}
137
138long fillOldEE(int count)
139{
140 TH2D hist("a", "a hist", 100, 0., 1., 5, 0., 10.);
141 for (int i = 0; i < count; ++i)
142 hist.Fill(0.611, 0.611);
143 return (long)hist.GetEntries();
144}
145
146long fillNEE(int count)
147{
148 RH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
149 std::vector<Hist::RCoordArray<2>> v(count);
150 for (int i = 0; i < count; ++i)
151 v[i] = {0.611, 0.611};
152 hist.FillN(v);
153 return hist.GetNDim();
154}
155
156long fillBufferedOldEE(int count)
157{
158 TH2D hist("a", "a hist", 100, 0., 1., 5, 0., 10.);
159 hist.SetBuffer(TH1::GetDefaultBufferSize());
160 for (int i = 0; i < count; ++i)
161 hist.Fill(0.611, 0.611);
162 return (long)hist.GetEntries();
163}
164
165long fillBufferedNewEE(int count)
166{
167 RH2D hist({{{100, 0., 1.}, {5, 0., 10.}}});
168 RHistBufferedFill<RH2D> filler(hist);
169 for (int i = 0; i < count; ++i)
170 filler.Fill({0.611, 0.611});
171 return hist.GetNDim();
172}
173
174using timefunc_t = std::add_pointer_t<long(int)>;
175
176void time1(timefunc_t run, int count, const std::string &name)
177{
178 using namespace std::chrono;
179 auto start = high_resolution_clock::now();
180 run(count);
181 auto end = high_resolution_clock::now();
182 duration<double> time_span = duration_cast<duration<double>>(end - start);
183
184 std::cout << count << " * " << name << ": " << time_span.count() << "seconds \n";
185}
186
187void time(timefunc_t r6, timefunc_t r7, int count, const std::string &name)
188{
189 time1(r6, count, name + " (ROOT6)");
190 time1(r7, count, name + " (ROOT7)");
191}
192
193void perfcomp()
194{
195 int factor = 1000000;
196 // factor = 1; // debug, fast!
197 time(createOldII, createNewII, factor, "create 2D hists [II]");
198 time(createOldEE, createNewEE, factor, "create 2D hists [EE]");
199 time(fillOldII, fillNewII, 100 * factor, "2D fills [II]");
200 time(fillOldEE, fillNewEE, 100 * factor, "2D fills [EE]");
201 time(fillBufferedOldII, fillBufferedNewII, 100 * factor, "2D fills (buffered) [II]");
202 time(fillBufferedOldEE, fillBufferedNewEE, 100 * factor, "2D fills (buffered) [EE]");
203}
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:4402
2-D histogram with a double per channel (see TH1 documentation)}
Definition TH2.h:300