45 #define STATCLASSES THistStatContent, THistStatUncertainty 50 using TimePoint_t = decltype( std::chrono::high_resolution_clock::now() );
56 Timer(
const char *title,
size_t count) : fTitle(title), fCount(count),
57 fStart(std::chrono::high_resolution_clock::now()) {}
60 using namespace std::chrono;
61 auto end = high_resolution_clock::now();
62 duration<double> time_span = duration_cast<duration<double>>(end - fStart);
65 std::cout << fCount <<
" * " << fTitle <<
"," << time_span.count() <<
",seconds ,";
66 std::cout << fCount / (1e6) / time_span.count() <<
",millions per seconds \n";
74 static constexpr
size_t fNBinsX = 4;
75 static constexpr
size_t fNBinsY = 5;
79 BinEdges(
double minValue,
double maxValue) {
80 if (maxValue < minValue)
swap(minValue,maxValue);
81 double range = maxValue - minValue;
83 double x[fNBinsX] = {0., 0.1, 0.3, 1.};
84 double y[fNBinsY] = {0., 0.1, 0.2, 0.3, 1.};
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];
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()); }
100 template <
typename T>
103 Timer t(
"GenerateInput",numbers.size());
104 if (minVal > maxVal) {
107 T range = maxVal - minVal;
109 size_t len = numbers.size();
110 for(
auto c = numbers.begin();
c != numbers.end(); ++
c) {
111 *
c = minVal + range * r.
Rndm();
120 std::string
result = std::string(version) +
" " + std::string(histname) +
" " + title.
to_string() +
" [" + axis.
to_string() +
"]";
124 template <
int dim,
typename type>
const char *
GetHist();
136 template <
typename T,
unsigned short kNDim>
struct Dim;
139 template <
typename T>
142 constexpr
static unsigned short kNDim = 2;
146 using InputType_t = double;
148 using FillFunc_t = std::add_pointer_t<long(ExpTH2 &hist, std::vector<InputType_t> &input,
std::string_view type)>;
152 static constexpr
const char *
const gType =
"regular bin size ";
154 template <FillFunc_t filler>
155 static long Execute(std::vector<InputType_t> &input,
double minVal,
double maxVal) {
158 for(
unsigned short i = 0; i <
gRepeat; ++ i) {
159 ExpTH2 hist({100, minVal, maxVal}, {5, minVal, maxVal});
160 result += filler(hist,input,gType);
167 static constexpr
const char *
const gType =
"irregular bin size";
169 template <FillFunc_t filler>
170 static long Execute(std::vector<InputType_t> &input,
double minVal,
double maxVal) {
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);
182 inline static long fillN(ExpTH2 &hist, std::vector<InputType_t> &input,
std::string_view gType) {
185 using array_t = std::array<InputType_t, 2>;
186 array_t *values = (array_t*)(&input[0]);
187 constexpr
size_t stride =
gStride;
189 std::string title =
MakeTitle(gVersion, GetHist<kNDim, T>(),
"fills N (stride 32)", gType);
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});
195 return hist.GetNDim();
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);
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]});
207 return hist.GetNDim();
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);
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]});
217 return hist.GetNDim();
222 template <
typename T>
225 constexpr
static unsigned short kNDim = 1;
229 using InputType_t = double;
231 using FillFunc_t = std::add_pointer_t<long(ExpTH1 &hist, std::vector<InputType_t> &input,
std::string_view type)>;
235 static constexpr
const char *
const gType =
"regular bin size ";
237 template <FillFunc_t filler>
238 static long Execute(std::vector<InputType_t> &input,
double minVal,
double maxVal) {
241 for(
unsigned short i = 0; i <
gRepeat; ++ i) {
242 ExpTH1 hist({100, minVal, maxVal});
243 result += filler(hist,input,gType);
250 static constexpr
const char *
const gType =
"irregular bin size";
252 template <FillFunc_t filler>
253 static long Execute(std::vector<InputType_t> &input,
double minVal,
double maxVal) {
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);
265 inline static long fillN(ExpTH1 &hist, std::vector<InputType_t> &input,
std::string_view gType) {
268 using array_t = std::array<InputType_t, 1>;
269 array_t *values = (array_t*)(&input[0]);
270 constexpr
size_t stride =
gStride;
272 std::string title =
MakeTitle(gVersion, GetHist<kNDim, T>(),
"fills N (stride 32)", gType);
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});
278 return hist.GetNDim();
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);
286 Timer t(title.c_str(),input.size());
287 for (
size_t i = 0; i < input.size(); ++i)
288 filler.Fill({input[i]});
290 return hist.GetNDim();
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);
296 Timer t(title.c_str(),input.size());
297 for (
size_t i = 0; i < input.size(); ++i)
298 hist.Fill({input[i]});
300 return hist.GetNDim();
312 const char *gVersion =
"R6";
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; };
320 template <
typename T,
int kNDim>
struct Dim;
322 template <
typename T>
325 constexpr
static unsigned short kNDim = 2;
326 using HistType_t =
typename Redirect<kNDim,T>::HistType_t;
329 using InputType_t = double;
331 using FillFunc_t = std::add_pointer_t<long(HistType_t &hist, std::vector<InputType_t> &input,
std::string_view type)>;
336 static constexpr
const char *
const gType =
"regular bin size ";
338 template <FillFunc_t filler>
339 static long Execute(std::vector<InputType_t> &input,
double minVal,
double maxVal) {
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);
352 static constexpr
const char *
const gType =
"irregular bin size";
354 template <FillFunc_t filler>
355 static long Execute(std::vector<InputType_t> &input,
double minVal,
double maxVal) {
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);
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);
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]);
377 return (
long)hist.GetEntries();
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;
386 Timer t(title.c_str(),input.size()/2);
387 for (
size_t i = 0; i < (input.size()-(stride*2-1)); i += (stride*2))
390 return (
long)hist.GetEntries();
394 std::string title =
MakeTitle(gVersion, GetHist<kNDim,T>(),
"fills ", gType);
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]);
401 return (
long)hist.GetEntries();
405 template <
typename T>
408 constexpr
static unsigned short kNDim = 1;
409 using HistType_t =
typename Redirect<kNDim,T>::HistType_t;
412 using InputType_t = double;
414 using FillFunc_t = std::add_pointer_t<long(HistType_t &hist, std::vector<InputType_t> &input,
std::string_view type)>;
419 static constexpr
const char *
const gType =
"regular bin size ";
421 template <FillFunc_t filler>
422 static long Execute(std::vector<InputType_t> &input,
double minVal,
double maxVal) {
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);
435 static constexpr
const char *
const gType =
"irregular bin size";
437 template <FillFunc_t filler>
438 static long Execute(std::vector<InputType_t> &input,
double minVal,
double maxVal) {
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);
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);
456 Timer t(title.c_str(),input.size());
457 for (
size_t i = 0; i < input.size()-1; ++i)
460 return (
long)hist.GetEntries();
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;
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);
473 return (
long)hist.GetEntries();
477 std::string title =
MakeTitle(gVersion, GetHist<kNDim,T>(),
"fills ", gType);
480 Timer t(title.c_str(),input.size());
481 for (
size_t i = 0; i < input.size(); ++i)
484 return (
long)hist.GetEntries();
489 template <
typename T,
unsigned short kNDim>
490 void speedtest(
size_t count = (
size_t)(1e6));
494 using DataType_t = double;
495 using InputType_t = double;
496 static constexpr
unsigned short kNDim = 2;
500 std::vector<InputType_t> input;
503 double minVal = -5.0;
504 double maxVal = +5.0;
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);
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);
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);
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);
543 using DataType_t = float;
544 using InputType_t = double;
545 constexpr
unsigned short kNDim = 2;
549 std::vector<InputType_t> input;
552 double minVal = -5.0;
553 double maxVal = +5.0;
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);
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);
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);
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);
588 using DataType_t = double;
589 using InputType_t = double;
590 static constexpr
unsigned short kNDim = 1;
594 std::vector<InputType_t> input;
597 double minVal = -5.0;
598 double maxVal = +5.0;
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);
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);
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);
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);
633 using DataType_t = float;
634 using InputType_t = double;
635 static constexpr
unsigned short kNDim = 1;
639 std::vector<InputType_t> input;
642 double minVal = -5.0;
643 double maxVal = +5.0;
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);
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);
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);
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);
685 int main(
int argc,
char **argv) {
689 if (argc > 1) iter = atof(argv[1]);
690 if (argc > 2) what = atoi(argv[2]);
void speedtest< float, 1 >(size_t count)
Random number generator class based on M.
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
virtual Double_t Rndm()
Machine independent random number generator.
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
void GenerateInput(std::vector< T > &numbers, double minVal, double maxVal, UInt_t seed)
constexpr unsigned short gRepeat
const char * GetHist< 2, double >()
const char * GetHist< 1, float >()
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
void speedtest< float, 2 >(size_t count)
const char * GetHist< 2, float >()
const char * GetHist< 1, double >()
Objects used to configure the different axis types.
RooCmdArg Timer(Bool_t flag=kTRUE)
void speedtest< double, 2 >(size_t count)
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
static Int_t GetDefaultBufferSize()
Static function return the default buffer size for automatic histograms the parameter fgBufferSize ma...
void speedtest(size_t count=(size_t)(1e6))
_LIBCPP_INLINE_VISIBILITY basic_string< _CharT, _Traits, _Allocator > to_string(const _Allocator &__a=_Allocator()) const
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
std::string MakeTitle(std::string_view version, std::string_view histname, std::string_view title, std::string_view axis)
void speedtest< double, 1 >(size_t count)
void histspeedtest(size_t iter, int what)
int main(int argc, char **argv)
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F