52#define STATCLASSES Experimental::RHistStatContent, Experimental::RHistStatUncertainty
56 using TimePoint_t =
decltype(std::chrono::high_resolution_clock::now());
62 Timer(
const char *title,
size_t count)
63 : fTitle(title), fCount(count), fStart(std::chrono::high_resolution_clock::now())
68 using namespace std::chrono;
69 auto end = high_resolution_clock::now();
70 duration<double> time_span = duration_cast<duration<double>>(end - fStart);
74 std::cout << fCount <<
" * " << fTitle <<
": " << time_span.count() <<
" seconds, \t";
75 std::cout << fCount / (1e6) / time_span.count() <<
" millions per seconds \n";
82 static constexpr size_t fNBinsX = 4;
83 static constexpr size_t fNBinsY = 5;
87 BinEdges(
double minValue,
double maxValue)
89 if (maxValue < minValue)
90 swap(minValue, maxValue);
91 double range = maxValue - minValue;
93 double x[fNBinsX] = {0., 0.1, 0.3, 1.};
94 double y[fNBinsY] = {0., 0.1, 0.2, 0.3, 1.};
96 for (
size_t i = 0; i < fNBinsX; ++i)
97 fXBins[i] = minValue + range *
x[i];
98 for (
size_t i = 0; i < fNBinsY; ++i)
99 fYBins[i] = minValue + range *
y[i];
104 AConf_t GetConfigX()
const {
return AConf_t(std::span<double>(fXBins).to_vector()); }
105 AConf_t GetConfigY()
const {
return AConf_t(std::span<double>(fYBins).to_vector()); }
111 Timer t(
"GenerateInput", numbers.size());
112 if (minVal > maxVal) {
115 T range = maxVal - minVal;
117 size_t len = numbers.size();
118 for (
auto c = numbers.begin();
c != numbers.end(); ++
c) {
119 *
c = minVal + range *
r.Rndm();
127 std::string(version) +
" " + std::string(histname) +
" " + std::string(title) +
" [" + std::string(axis) +
"]";
131template <
int dim,
typename type>
159template <
typename T,
unsigned short kNDim>
165 constexpr static unsigned short kNDim = 2;
168 using FillFunc_t = std::add_pointer_t<long(ExpTH2 &hist, std::vector<double> &input,
std::string_view type)>;
171 static constexpr const char *
const gType =
"regular bin size ";
173 template <FillFunc_t filler>
174 static long Execute(std::vector<double> &input,
double minVal,
double maxVal)
177 ExpTH2 hist({100, minVal, maxVal}, {5, minVal, maxVal});
178 return filler(hist, input,
gType);
183 static constexpr const char *
const gType =
"irregular bin size";
185 template <FillFunc_t filler>
186 static long Execute(std::vector<double> &input,
double minVal,
double maxVal)
189 BinEdges edges(minVal, maxVal);
190 ExpTH2 hist(edges.GetConfigX(), edges.GetConfigY());
191 return filler(hist, input,
gType);
199 array_t *values = (array_t *)(&input[0]);
200 constexpr size_t stride =
gStride;
204 Timer t(title.c_str(), input.size() / 2);
205 for (
size_t i = 0; i < (input.size() - (stride * 2 - 1)); i += (stride * 2), values += 32) {
206 std::span<array_t> coords(values, 32);
210 return hist.GetNDim();
218 Timer t(title.c_str(), input.size() / 2);
219 for (
size_t i = 0; i < input.size() - 1; i += 2)
220 filler.Fill({input[i], input[i + 1]});
222 return hist.GetNDim();
229 Timer t(title.c_str(), input.size() / 2);
230 for (
size_t i = 0; i < input.size() - 1; i += 2)
231 hist.Fill({input[i], input[i + 1]});
233 return hist.GetNDim();
240 constexpr static unsigned short kNDim = 1;
243 using FillFunc_t = std::add_pointer_t<long(ExpTH1 &hist, std::vector<double> &input,
std::string_view type)>;
246 static constexpr const char *
const gType =
"regular bin size ";
248 template <FillFunc_t filler>
249 static long Execute(std::vector<double> &input,
double minVal,
double maxVal)
252 for (
unsigned short i = 0; i <
gRepeat; ++i) {
253 ExpTH1 hist({100, minVal, maxVal});
254 result += filler(hist, input,
gType);
261 static constexpr const char *
const gType =
"irregular bin size";
263 template <FillFunc_t filler>
264 static long Execute(std::vector<double> &input,
double minVal,
double maxVal)
268 BinEdges edges(minVal, maxVal);
269 for (
unsigned short i = 0; i <
gRepeat; ++i) {
270 ExpTH1 hist(edges.GetConfigX());
271 result += filler(hist, input,
gType);
281 array_t *values = (array_t *)(&input[0]);
282 constexpr size_t stride =
gStride;
286 Timer t(title.c_str(), input.size());
287 for (
size_t i = 0; i < (input.size() - (stride - 1)); i += (stride), values += 32) {
288 std::span<array_t> coords(values, 32);
292 return hist.GetNDim();
300 Timer t(title.c_str(), input.size());
301 for (
size_t i = 0; i < input.size(); ++i)
302 filler.Fill({input[i]});
304 return hist.GetNDim();
311 Timer t(title.c_str(), input.size());
312 for (
size_t i = 0; i < input.size(); ++i)
313 hist.Fill({input[i]});
315 return hist.GetNDim();
324template <
int ndim,
typename T>
327struct Redirect<2, float> {
328 using HistType_t =
TH2F;
331struct Redirect<2, double> {
332 using HistType_t =
TH2D;
335struct Redirect<1, float> {
336 using HistType_t =
TH1F;
339struct Redirect<1, double> {
340 using HistType_t =
TH1D;
343template <
typename T,
int kNDim>
349 constexpr static unsigned short kNDim = 2;
350 using HistType_t =
typename Redirect<kNDim, T>::HistType_t;
352 using FillFunc_t = std::add_pointer_t<long(HistType_t &hist, std::vector<double> &input,
std::string_view type)>;
356 static constexpr const char *
const gType =
"regular bin size ";
358 template <FillFunc_t filler>
359 static long Execute(std::vector<double> &input,
double minVal,
double maxVal)
363 for (
unsigned short i = 0; i <
gRepeat; ++i) {
364 HistType_t hist(
"a",
"a hist", 100, minVal, maxVal, 5, minVal, maxVal);
365 result += filler(hist, input,
gType);
373 static constexpr const char *
const gType =
"irregular bin size";
375 template <FillFunc_t filler>
376 static long Execute(std::vector<double> &input,
double minVal,
double maxVal)
379 BinEdges edges(minVal, maxVal);
380 for (
unsigned short i = 0; i <
gRepeat; ++i) {
381 HistType_t hist(
"a",
"a hist", edges.fNBinsX - 1, edges.fXBins, edges.fNBinsY - 1, edges.fYBins);
382 result += filler(hist, input,
gType);
394 Timer t(title.c_str(), input.size() / 2);
395 for (
size_t i = 0; i < input.size() - 1; i += 2)
396 hist.Fill(input[i], input[i + 1]);
398 return (
long)hist.GetEntries();
404 constexpr size_t stride =
gStride;
407 Timer t(title.c_str(), input.size() / 2);
408 for (
size_t i = 0; i < (input.size() - (stride * 2 - 1)); i += (stride * 2))
411 return (
long)hist.GetEntries();
419 Timer t(title.c_str(), input.size() / 2);
420 for (
size_t i = 0; i < input.size() - 1; i += 2)
421 hist.Fill(input[i], input[i + 1]);
423 return (
long)hist.GetEntries();
430 constexpr static unsigned short kNDim = 1;
431 using HistType_t =
typename Redirect<kNDim, T>::HistType_t;
433 using FillFunc_t = std::add_pointer_t<long(HistType_t &hist, std::vector<double> &input,
std::string_view type)>;
437 static constexpr const char *
const gType =
"regular bin size ";
439 template <FillFunc_t filler>
440 static long Execute(std::vector<double> &input,
double minVal,
double maxVal)
444 for (
unsigned short i = 0; i <
gRepeat; ++i) {
445 HistType_t hist(
"a",
"a hist", 100, minVal, maxVal);
446 result += filler(hist, input,
gType);
454 static constexpr const char *
const gType =
"irregular bin size";
456 template <FillFunc_t filler>
457 static long Execute(std::vector<double> &input,
double minVal,
double maxVal)
460 BinEdges edges(minVal, maxVal);
461 for (
unsigned short i = 0; i <
gRepeat; ++i) {
462 HistType_t hist(
"a",
"a hist", edges.fNBinsX - 1, edges.fXBins);
463 result += filler(hist, input,
gType);
475 Timer t(title.c_str(), input.size());
476 for (
size_t i = 0; i < input.size() - 1; ++i)
479 return (
long)hist.GetEntries();
485 constexpr size_t stride =
gStride;
488 Timer t(title.c_str(), input.size());
489 for (
size_t i = 0; i < (input.size() - (stride - 1)); i += (stride))
490 hist.FillN(
gStride, &(input[i]),
nullptr);
492 return (
long)hist.GetEntries();
500 Timer t(title.c_str(), input.size());
501 for (
size_t i = 0; i < input.size(); ++i)
504 return (
long)hist.GetEntries();
509template <
typename T,
unsigned short kNDim>
515 using DataType_t = double;
516 static constexpr unsigned short kNDim = 2;
520 std::vector<double> input;
523 double minVal = -5.0;
524 double maxVal = +5.0;
533 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
534 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
535 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
536 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
542 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
543 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
544 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
545 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
551 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
552 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
553 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
554 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
560 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
561 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
562 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
563 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
575 using DataType_t = float;
576 constexpr unsigned short kNDim = 2;
580 std::vector<double> input;
583 double minVal = -5.0;
584 double maxVal = +5.0;
593 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
594 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
595 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
596 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
602 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
603 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
604 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
605 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
611 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
612 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
613 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
614 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
620 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
621 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
622 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
623 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
631 using DataType_t = double;
632 static constexpr unsigned short kNDim = 1;
636 std::vector<double> input;
639 double minVal = -5.0;
640 double maxVal = +5.0;
649 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
650 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
651 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
652 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>::fillBuffered>(input, minVal, maxVal);
660 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
661 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
667 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
668 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
669 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
670 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
676 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
677 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
678 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
679 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
687 using DataType_t = float;
688 static constexpr unsigned short kNDim = 1;
692 std::vector<double> input;
695 double minVal = -5.0;
696 double maxVal = +5.0;
705 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
706 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
707 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
708 R7::Dim<DataType_t, kNDim>::EE::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
714 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
715 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
716 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
717 R7::Dim<DataType_t, kNDim>::II::Execute<R7::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
723 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
724 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
725 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
726 R6::Dim<DataType_t, kNDim>::EE::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
732 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
733 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillBuffered>(input, minVal, maxVal);
734 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
735 R6::Dim<DataType_t, kNDim>::II::Execute<R6::Dim<DataType_t, kNDim>::fillN>(input, minVal, maxVal);
756 int what = 1 | 2 | 4 | 8;
758 iter = atof(argv[1]);
760 what = atoi(argv[2]);
Objects used to configure the different axis types.
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
1-D histogram with a double per channel (see TH1 documentation)}
1-D histogram with a float per channel (see TH1 documentation)}
static Int_t GetDefaultBufferSize()
Static function return the default buffer size for automatic histograms the parameter fgBufferSize ma...
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
2-D histogram with a double per channel (see TH1 documentation)}
2-D histogram with a float per channel (see TH1 documentation)}
Random number generator class based on M.
const char * GetHist< 1, double >()
void speedtest(size_t count=(size_t)(1e6))
int main(int argc, char **argv)
const char * GetHist< 2, double >()
void speedtest< double, 1 >(size_t count)
constexpr unsigned short gRepeat
void speedtest< float, 1 >(size_t count)
const char * GetHist< 2, float >()
const char * GetHist< 1, float >()
void histspeedtest(size_t iter=1e6, int what=255)
void GenerateInput(std::vector< T > &numbers, double minVal, double maxVal, UInt_t seed)
std::string MakeTitle(std::string_view version, std::string_view histname, std::string_view title, std::string_view axis)
void speedtest< double, 2 >(size_t count)
void speedtest< float, 2 >(size_t count)
basic_string_view< char > string_view
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
Namespace for new ROOT classes and functions.
RooCmdArg Timer(Bool_t flag=kTRUE)