forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_Types.cxx
More file actions
741 lines (670 loc) · 28.6 KB
/
benchmark_Types.cxx
File metadata and controls
741 lines (670 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include <TObjArray.h>
#include <TH1.h>
#include <TH2.h>
#include <TH3.h>
#include <TTree.h>
#include <THnSparse.h>
#include <TF1.h>
#include <TF2.h>
#include <TF3.h>
#include <TRandom.h>
#include <TRandomGen.h>
#include <chrono>
#include <ctime>
#include <TMessage.h>
#include "Framework/TMessageSerializer.h"
#include <type_traits>
#include <iostream>
#include <fstream>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/histogram.hpp>
#include <boost/histogram/serialization.hpp>
#include <sstream>
namespace bh = boost::histogram;
enum class Measurement {
Size,
SizeAfterSerialisation,
Deserialisation,
Merging,
Serialisation
};
struct Results {
size_t sizeBytes = 0;
size_t sizeSerialisedBytes = 0;
double deserialisationSeconds = 0;
double mergingSeconds = 0;
double serialisationSeconds = 0;
};
struct Parameters {
constexpr static Parameters forHistograms(size_t objectSize, size_t entries)
{
return {objectSize, 0, 0, entries};
}
constexpr static Parameters forSparse(size_t bins, size_t dimensions, size_t entries)
{
return {0, bins, dimensions, entries};
}
constexpr static Parameters forTrees(size_t branches, size_t branchSize, size_t entries)
{
return {0, 0, 0, entries, branches, branchSize};
}
size_t objectSize = 0;
size_t bins = 0;
size_t dimensions = 0;
size_t entries = 0;
size_t branches = 0;
size_t branchSize = 0;
};
auto measure = [](Measurement m, auto* o, auto* i) -> double {
switch (m) {
case Measurement::Size: {
const double scale = 1.0; //000000000.0;
if constexpr (std::is_base_of<TObject, typename std::remove_pointer<decltype(o)>::type>::value) {
if (o->InheritsFrom(TH1::Class())) {
// this includes TH1, TH2, TH3
// i don't see an easy way to find out the size of a cell, i assume that they are Int
return reinterpret_cast<TH1*>(o)->GetNcells() * sizeof(Int_t) / scale;
} else if (o->InheritsFrom(THnSparse::Class())) {
auto* sparse = reinterpret_cast<THnSparse*>(o);
// this is has to be multiplied with bin (entry) size, but we cannot get it from th einterface.
return sparse->GetNChunks() * sparse->GetChunkSize() / scale;
} else if (o->InheritsFrom(THnBase::Class())) {
// this includes THn and THnSparse
return reinterpret_cast<THnBase*>(o)->GetNbins() * sizeof(Int_t) / scale;
} else if (o->InheritsFrom(TTree::Class())) {
size_t totalSize = 0;
auto tree = reinterpret_cast<TTree*>(o);
auto branchList = tree->GetListOfBranches();
for (const auto* branch : *branchList) {
totalSize += dynamic_cast<const TBranch*>(branch)->GetTotalSize();
}
return totalSize / scale;
} else {
throw std::runtime_error("Object with type '" + std::string(o->ClassName()) + "' is not one of the mergeable types.");
}
} else {
// boost
return o->size() * sizeof(int);
}
}
case Measurement::Merging: {
auto end = std::chrono::high_resolution_clock::now();
auto start = std::chrono::high_resolution_clock::now();
if constexpr (std::is_base_of<TObject, typename std::remove_pointer<decltype(o)>::type>::value) {
if (o->InheritsFrom(TH1::Class())) {
// this includes TH1, TH2, TH3
start = std::chrono::high_resolution_clock::now();
reinterpret_cast<TH1*>(o)->Merge(i, "-NOCHECK");
} else if (o->InheritsFrom(THnBase::Class())) {
// this includes THn and THnSparse
start = std::chrono::high_resolution_clock::now();
reinterpret_cast<THnBase*>(o)->Merge(i);
} else if (o->InheritsFrom(TTree::Class())) {
start = std::chrono::high_resolution_clock::now();
reinterpret_cast<TTree*>(o)->Merge(i);
} else {
throw std::runtime_error("Object with type '" + std::string(o->ClassName()) + "' is not one of the mergeable types.");
}
end = std::chrono::high_resolution_clock::now();
} else {
// boost
*o += *i;
end = std::chrono::high_resolution_clock::now();
(void)*o;
}
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
return elapsed_seconds.count();
}
case Measurement::Serialisation: {
auto end = std::chrono::high_resolution_clock::now();
auto start = std::chrono::high_resolution_clock::now();
if constexpr (std::is_base_of<TObject, typename std::remove_pointer<decltype(o)>::type>::value) {
TMessage* tm = new TMessage(kMESS_OBJECT);
tm->WriteObject(o);
end = std::chrono::high_resolution_clock::now();
(void)*tm;
delete tm;
} else {
// boost
std::ostringstream os;
std::string buf;
boost::archive::binary_oarchive oa(os);
oa << *o;
end = std::chrono::high_resolution_clock::now();
(void)os; // hopefully this will prevent from optimising this code out.
}
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
return elapsed_seconds.count();
}
case Measurement::Deserialisation: {
auto start = std::chrono::high_resolution_clock::now();
auto end = std::chrono::high_resolution_clock::now();
if constexpr (std::is_base_of<TObject, typename std::remove_pointer<decltype(o)>::type>::value) {
TMessage* tm = new TMessage(kMESS_OBJECT);
tm->WriteObject(o);
start = std::chrono::high_resolution_clock::now();
o2::framework::FairTMessage ftm(const_cast<char*>(tm->Buffer()), tm->BufferSize());
auto* storedClass = ftm.GetClass();
if (storedClass == nullptr) {
throw std::runtime_error("Unknown stored class");
}
auto* tObjectClass = TClass::GetClass(typeid(TObject));
if (!storedClass->InheritsFrom(tObjectClass)) {
throw std::runtime_error("Class '" + std::string(storedClass->GetName()) + "'does not inherit from TObject");
}
auto* object = ftm.ReadObjectAny(storedClass);
if (object == nullptr) {
throw std::runtime_error("Failed to read object with name '" + std::string(storedClass->GetName()) + "' from message using ROOT serialization.");
}
auto tobject = static_cast<TObject*>(object);
end = std::chrono::high_resolution_clock::now();
(void)*tobject;
delete tm;
delete tobject;
} else {
std::ostringstream os;
std::string buf;
boost::archive::binary_oarchive oa(os);
oa << *o;
buf = os.str();
start = std::chrono::high_resolution_clock::now();
auto deserialisedHistogram = typename std::remove_pointer<decltype(o)>::type();
std::istringstream is(buf);
boost::archive::binary_iarchive ia(is);
ia >> deserialisedHistogram;
end = std::chrono::high_resolution_clock::now();
assert(deserialisedHistogram == *o);
}
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
return elapsed_seconds.count();
}
case Measurement::SizeAfterSerialisation: {
const double scale = 1.0; //1000000000.0;
if constexpr (std::is_base_of<TObject, typename std::remove_pointer<decltype(o)>::type>::value) {
TMessage* tm = new TMessage(kMESS_OBJECT);
tm->WriteObject(o);
auto serialisedSize = tm->BufferSize();
delete tm;
return serialisedSize / scale;
} else {
std::ostringstream os;
std::string buf;
boost::archive::binary_oarchive oa(os);
oa << *i;
buf = os.str();
return buf.size() / scale;
}
}
}
throw;
};
static std::vector<Results> BM_TH1I(size_t repetitions, const Parameters p)
{
const size_t objSize = p.objectSize;
const size_t entries = p.entries;
const size_t bins = objSize / sizeof(Int_t);
auto m = std::make_unique<TH1I>("merged", "merged", bins, 0, 1000000);
// avoid memory overcommitment by doing something with data.
for (size_t i = 0; i < bins; i++) {
m->SetBinContent(i, 1);
}
std::unique_ptr<TCollection> collection = std::make_unique<TObjArray>();
collection->SetOwner(true);
auto uni = std::make_unique<TF1>("uni", "1", 0, 1000000);
TH1I* h = new TH1I("test", "test", bins, 0, 1000000);
collection->Add(h);
std::vector<Results> allResults;
for (size_t r = 0; r < repetitions; r++) {
h->Reset();
h->FillRandom("uni", entries);
Results iterationResults;
iterationResults.sizeBytes = measure(Measurement::Size, m.get(), collection.get());
iterationResults.sizeSerialisedBytes = measure(Measurement::SizeAfterSerialisation, m.get(), collection.get());
iterationResults.deserialisationSeconds = measure(Measurement::Deserialisation, m.get(), collection.get());
iterationResults.serialisationSeconds = measure(Measurement::Serialisation, m.get(), collection.get());
iterationResults.mergingSeconds = measure(Measurement::Merging, m.get(), collection.get());
allResults.push_back(iterationResults);
}
return allResults;
}
static std::vector<Results> BM_TH2I(size_t repetitions, const Parameters p)
{
const size_t objSize = p.objectSize;
const size_t entries = p.entries;
const size_t bins = std::sqrt(objSize / sizeof(Int_t));
auto m = std::make_unique<TH2I>("merged", "merged", bins, 0, 1000000, bins, 0, 1000000);
// avoid memory overcommitment by doing something with data.
for (size_t i = 0; i < bins * bins; i++) {
m->SetBinContent(i, 1);
}
std::unique_ptr<TCollection> collection = std::make_unique<TObjArray>();
collection->SetOwner(true);
auto uni = std::make_unique<TF2>("uni", "1", 0, 1000000, 0, 1000000);
auto* h = new TH2I("test", "test", bins, 0, 1000000, bins, 0, 1000000);
collection->Add(h);
std::vector<Results> allResults;
for (size_t r = 0; r < repetitions; r++) {
h->Reset();
h->FillRandom("uni", entries);
Results iterationResults;
iterationResults.sizeBytes = measure(Measurement::Size, m.get(), collection.get());
iterationResults.sizeSerialisedBytes = measure(Measurement::SizeAfterSerialisation, m.get(), collection.get());
iterationResults.deserialisationSeconds = measure(Measurement::Deserialisation, m.get(), collection.get());
iterationResults.serialisationSeconds = measure(Measurement::Serialisation, m.get(), collection.get());
iterationResults.mergingSeconds = measure(Measurement::Merging, m.get(), collection.get());
allResults.push_back(iterationResults);
}
return allResults;
}
static std::vector<Results> BM_TH3I(size_t repetitions, const Parameters p)
{
const size_t objSize = p.objectSize;
const size_t entries = p.entries;
const size_t bins = std::pow(objSize / sizeof(Int_t), 1 / 3.0);
auto m = std::make_unique<TH3I>("merged", "merged", bins, 0, 1000000, bins, 0, 1000000, bins, 0, 1000000);
// avoid memory overcommitment by doing something with data.
for (size_t i = 0; i < bins * bins * bins; i++) {
m->SetBinContent(i, 1);
}
std::unique_ptr<TCollection> collection = std::make_unique<TObjArray>();
collection->SetOwner(true);
auto uni = std::make_unique<TF3>("uni", "1", 0, 1000000, 0, 1000000, 0, 1000000);
auto* h = new TH3I("test", "test", bins, 0, 1000000, bins, 0, 1000000, bins, 0, 1000000);
collection->Add(h);
std::vector<Results> allResults;
for (size_t r = 0; r < repetitions; r++) {
h->Reset();
h->FillRandom("uni", entries);
Results iterationResults;
iterationResults.sizeBytes = measure(Measurement::Size, m.get(), collection.get());
iterationResults.sizeSerialisedBytes = measure(Measurement::SizeAfterSerialisation, m.get(), collection.get());
iterationResults.deserialisationSeconds = measure(Measurement::Deserialisation, m.get(), collection.get());
iterationResults.serialisationSeconds = measure(Measurement::Serialisation, m.get(), collection.get());
iterationResults.mergingSeconds = measure(Measurement::Merging, m.get(), collection.get());
allResults.push_back(iterationResults);
}
return allResults;
}
template <typename storageT>
static std::vector<Results> BM_BoostRegular1D(size_t repetitions, const Parameters p)
{
const size_t entries = p.entries;
const size_t bins = p.objectSize / sizeof(int32_t);
const double min = 0.0;
const double max = 1000000.0;
auto merged = bh::make_histogram_with(storageT(), bh::axis::regular<>(bins, min, max, "x"));
merged += merged; // avoid memory overcommitment by doing something with data.
using HistoType = decltype(merged);
TRandomMixMax gen;
gen.SetSeed(std::random_device()());
Double_t randomArray[entries];
std::vector<Results> allResults;
for (size_t r = 0; r < repetitions; r++) {
auto h = bh::make_histogram_with(storageT(), bh::axis::regular<>(bins, min, max, "x"));
gen.RndmArray(entries, randomArray);
for (double rnd : randomArray) {
h(rnd * max);
}
Results iterationResults;
iterationResults.sizeBytes = measure(Measurement::Size, &merged, &h);
iterationResults.sizeSerialisedBytes = measure(Measurement::SizeAfterSerialisation, &merged, &h);
iterationResults.deserialisationSeconds = measure(Measurement::Deserialisation, &merged, &h);
iterationResults.serialisationSeconds = measure(Measurement::Serialisation, &merged, &h);
iterationResults.mergingSeconds = measure(Measurement::Merging, &merged, &h);
allResults.push_back(iterationResults);
}
return allResults;
}
template <typename storageT>
static std::vector<Results> BM_BoostRegular2D(size_t repetitions, const Parameters p)
{
const size_t entries = p.entries;
const size_t bins = std::sqrt(p.objectSize / sizeof(int32_t));
const double min = 0.0;
const double max = 1000000.0;
auto merged = bh::make_histogram_with(storageT(), bh::axis::regular<>(bins, min, max, "x"), bh::axis::regular<>(bins, min, max, "y"));
merged += merged; // avoid memory overcommitment by doing something with data.
TRandomMixMax gen;
gen.SetSeed(std::random_device()());
Double_t randomArrayX[entries];
Double_t randomArrayY[entries];
std::vector<Results> allResults;
for (size_t r = 0; r < repetitions; r++) {
auto h = bh::make_histogram_with(storageT(), bh::axis::regular<>(bins, min, max, "x"), bh::axis::regular<>(bins, min, max, "y"));
gen.RndmArray(entries, randomArrayX);
gen.RndmArray(entries, randomArrayY);
for (size_t rnd = 0; rnd < entries; rnd++) {
h(randomArrayX[rnd] * max, randomArrayY[rnd] * max);
}
Results iterationResults;
iterationResults.sizeBytes = measure(Measurement::Size, &merged, &h);
iterationResults.sizeSerialisedBytes = measure(Measurement::SizeAfterSerialisation, &merged, &h);
iterationResults.deserialisationSeconds = measure(Measurement::Deserialisation, &merged, &h);
iterationResults.serialisationSeconds = measure(Measurement::Serialisation, &merged, &h);
iterationResults.mergingSeconds = measure(Measurement::Merging, &merged, &h);
allResults.push_back(iterationResults);
}
return allResults;
}
static std::vector<Results> BM_THNSparseI(size_t repetitions, const Parameters p)
{
const size_t bins = p.bins;
const size_t dim = p.dimensions;
const size_t entries = p.entries;
const Double_t min = 0.0;
const Double_t max = 1000000.0;
const std::vector<Int_t> binsDims(dim, bins);
const std::vector<Double_t> mins(dim, min);
const std::vector<Double_t> maxs(dim, max);
TRandomMixMax gen;
gen.SetSeed(std::random_device()());
Double_t randomArray[dim];
std::vector<Results> allResults;
for (size_t rep = 0; rep < repetitions; rep++) {
// histograms have to be created in each loop repetition, otherwise i get strange segfaults with large number of entries.
std::unique_ptr<TCollection> collection = std::make_unique<TObjArray>();
collection->SetOwner(true);
auto* h = new THnSparseI("test", "test", dim, binsDims.data(), mins.data(), maxs.data());
collection->Add(h);
auto m = std::make_unique<THnSparseI>("merged", "merged", dim, binsDims.data(), mins.data(), maxs.data());
for (size_t entry = 0; entry < entries; entry++) {
gen.RndmArray(dim, randomArray);
for (double& r : randomArray) {
r *= max;
}
h->Fill(randomArray);
}
for (size_t entry = 0; entry < entries; entry++) {
gen.RndmArray(dim, randomArray);
for (double& r : randomArray) {
r *= max;
}
m->Fill(randomArray);
}
Results iterationResults;
iterationResults.sizeBytes = measure(Measurement::Size, m.get(), collection.get());
iterationResults.sizeSerialisedBytes = measure(Measurement::SizeAfterSerialisation, m.get(), collection.get());
iterationResults.deserialisationSeconds = measure(Measurement::Deserialisation, m.get(), collection.get());
iterationResults.serialisationSeconds = measure(Measurement::Serialisation, m.get(), collection.get());
iterationResults.mergingSeconds = measure(Measurement::Merging, m.get(), collection.get());
allResults.push_back(iterationResults);
}
return allResults;
}
static std::vector<Results> BM_TTree(size_t repetitions, const Parameters p)
{
const size_t branchSize = p.branchSize;
const size_t branches = p.branches;
const size_t entries = p.entries;
using branch_t = std::vector<uint64_t>;
std::vector<branch_t> branchCollection;
for (size_t i = 0; i < branches; i++) {
branchCollection.emplace_back(branchSize, 0);
}
auto createTree = [&](std::string name) -> TTree* {
TTree* tree = new TTree();
for (size_t i = 0; i < branchCollection.size(); i++) {
tree->Branch(("b" + std::to_string(i)).c_str(),
&branchCollection[i],
("array" + std::to_string(i) + "[" + std::to_string(branchSize) + "]:l").c_str());
}
tree->SetName(name.c_str());
return tree;
};
auto fillTree = [&](TTree* t) {
TRandomMixMax gen;
gen.SetSeed(std::random_device()());
Float_t randomArray[branchSize];
for (size_t entry = 0; entry < entries; entry++) {
for (auto& branch : branchCollection) {
gen.RndmArray(branchSize, randomArray);
for (size_t i = 0; i < branchSize; i++) {
branch[i] = static_cast<uint64_t>(randomArray[i]);
}
}
t->Fill();
}
};
std::vector<Results> allResults;
for (size_t r = 0; r < repetitions; r++) {
std::unique_ptr<TCollection> collection = std::make_unique<TObjArray>();
collection->SetOwner(true);
TTree* t = createTree("input");
fillTree(t);
collection->Add(t);
TTree* m = createTree("merged");
fillTree(m);
Results iterationResults;
iterationResults.sizeBytes = measure(Measurement::Size, m, collection.get());
iterationResults.sizeSerialisedBytes = measure(Measurement::SizeAfterSerialisation, m, collection.get());
iterationResults.deserialisationSeconds = measure(Measurement::Deserialisation, m, collection.get());
iterationResults.serialisationSeconds = measure(Measurement::Serialisation, m, collection.get());
iterationResults.mergingSeconds = measure(Measurement::Merging, m, collection.get());
allResults.push_back(iterationResults);
delete m;
}
return allResults;
}
void printHeaderCSV(std::ostream& out)
{
out << "name,"
"objectSize,bins,dimensions,entries,branches,branchSize,"
"sizeBytes,sizeSerialisedBytes,deserialisationSeconds,mergingSeconds,serialisationSeconds"
"\n";
}
void printResultsCSV(std::ostream& out, std::string name, const Parameters& p, const std::vector<Results>& results)
{
for (const auto r : results) {
out << name << ","
<< p.objectSize << "," << p.bins << "," << p.dimensions << "," << p.entries << "," << p.branches << "," << p.branchSize << ","
<< r.sizeBytes << "," << r.sizeSerialisedBytes << "," << r.deserialisationSeconds << "," << r.mergingSeconds << "," << r.serialisationSeconds
<< '\n';
}
}
int main(int argc, const char* argv[])
{
if (argc < 2) {
throw std::runtime_error("Output file name expected");
}
std::ofstream file;
file.open(argv[1]);
printHeaderCSV(file);
printHeaderCSV(std::cout);
size_t repetitions = argc < 3 ? 1 : std::atoll(argv[2]);
{
// TH1I
std::vector<Parameters> parameters{
Parameters::forHistograms(8 << 0, 50000),
Parameters::forHistograms(8 << 3, 50000),
Parameters::forHistograms(8 << 6, 50000),
Parameters::forHistograms(8 << 9, 50000),
Parameters::forHistograms(8 << 12, 50000),
Parameters::forHistograms(8 << 15, 50000),
Parameters::forHistograms(8 << 18, 50000),
Parameters::forHistograms(8 << 21, 50000)};
for (const auto& p : parameters) {
auto results = BM_TH1I(repetitions, p);
printResultsCSV(file, "TH1I", p, results);
printResultsCSV(std::cout, "TH1I", p, results);
}
}
{
// TH2I
std::vector<Parameters> parameters{
Parameters::forHistograms(8 << 0, 50000),
Parameters::forHistograms(8 << 3, 50000),
Parameters::forHistograms(8 << 6, 50000),
Parameters::forHistograms(8 << 9, 50000),
Parameters::forHistograms(8 << 12, 50000),
Parameters::forHistograms(8 << 15, 50000),
Parameters::forHistograms(8 << 18, 50000),
Parameters::forHistograms(8 << 21, 50000)};
for (const auto& p : parameters) {
auto results = BM_TH2I(repetitions, p);
printResultsCSV(file, "TH2I", p, results);
printResultsCSV(std::cout, "TH2I", p, results);
}
}
{
// TH3I
std::vector<Parameters> parameters{
Parameters::forHistograms(8 << 0, 50000),
Parameters::forHistograms(8 << 3, 50000),
Parameters::forHistograms(8 << 6, 50000),
Parameters::forHistograms(8 << 9, 50000),
Parameters::forHistograms(8 << 12, 50000),
Parameters::forHistograms(8 << 15, 50000),
Parameters::forHistograms(8 << 18, 50000),
Parameters::forHistograms(8 << 21, 50000)};
for (const auto& p : parameters) {
auto results = BM_TH3I(repetitions, p);
printResultsCSV(file, "TH3I", p, results);
printResultsCSV(std::cout, "TH3I", p, results);
}
}
{
// THnSparseI
std::vector<Parameters> parameters{
Parameters::forSparse(8, 8, 512),
Parameters::forSparse(64, 8, 512),
Parameters::forSparse(512, 8, 512),
Parameters::forSparse(4096, 8, 512),
Parameters::forSparse(32768, 8, 512),
Parameters::forSparse(512, 2, 512),
Parameters::forSparse(512, 4, 512),
Parameters::forSparse(512, 8, 512),
Parameters::forSparse(512, 16, 512),
Parameters::forSparse(512, 32, 512),
Parameters::forSparse(512, 64, 512),
Parameters::forSparse(512, 8, 1),
Parameters::forSparse(512, 8, 8),
Parameters::forSparse(512, 8, 64),
Parameters::forSparse(512, 8, 512),
Parameters::forSparse(512, 8, 4096),
Parameters::forSparse(512, 8, 32768),
Parameters::forSparse(512, 8, 262144),
Parameters::forSparse(512, 8, 2097152),
// Parameters::forSparse(512, 8, 16777216),
Parameters::forSparse(32, 4, 1),
Parameters::forSparse(32, 4, 8),
Parameters::forSparse(32, 4, 64),
Parameters::forSparse(32, 4, 512),
Parameters::forSparse(32, 4, 4096),
Parameters::forSparse(32, 4, 32768),
Parameters::forSparse(32, 4, 262144),
Parameters::forSparse(32, 4, 2097152),
Parameters::forSparse(32, 4, 16777216)};
for (const auto& p : parameters) {
auto results = BM_THNSparseI(repetitions, p);
printResultsCSV(file, "THnSparseI", p, results);
printResultsCSV(std::cout, "THnSparseI", p, results);
}
}
{
// TTree
std::vector<Parameters> parameters{
Parameters::forTrees(8, 8, 8),
Parameters::forTrees(8, 8, 8 << 3),
Parameters::forTrees(8, 8, 8 << 6),
Parameters::forTrees(8, 8, 8 << 9),
Parameters::forTrees(8, 8, 8 << 12),
Parameters::forTrees(8, 8, 8 << 15),
Parameters::forTrees(8, 8, 8 << 18),
Parameters::forTrees(8, 1 << 0, 8 << 12),
Parameters::forTrees(8, 1 << 2, 8 << 12),
Parameters::forTrees(8, 1 << 4, 8 << 12),
Parameters::forTrees(8, 1 << 6, 8 << 12),
Parameters::forTrees(8, 1 << 8, 8 << 12),
Parameters::forTrees(1 << 0, 8, 8 << 12),
Parameters::forTrees(1 << 2, 8, 8 << 12),
Parameters::forTrees(1 << 4, 8, 8 << 12),
Parameters::forTrees(1 << 6, 8, 8 << 12),
Parameters::forTrees(1 << 8, 8, 8 << 12)};
for (const auto& p : parameters) {
auto results = BM_TTree(repetitions, p);
printResultsCSV(file, "TTree", p, results);
printResultsCSV(std::cout, "TTree", p, results);
}
}
{
// boost regular 1D. We use a combination of template and macro to be able to use static storage (std::array) with different parameters.
#define BM_BOOST1DARRAY_FOR(objSize, entries) \
{ \
constexpr auto p = Parameters::forHistograms(objSize, entries); \
auto results = BM_BoostRegular1D<std::array<int32_t, p.objectSize / sizeof(int32_t) + 2>>(repetitions, p); \
printResultsCSV(file, "BoostRegular1DArray", p, results); \
printResultsCSV(std::cout, "BoostRegular1DArray", p, results); \
}
BM_BOOST1DARRAY_FOR(8 << 0, 50000);
BM_BOOST1DARRAY_FOR(8 << 3, 50000);
BM_BOOST1DARRAY_FOR(8 << 6, 50000);
BM_BOOST1DARRAY_FOR(8 << 9, 50000);
BM_BOOST1DARRAY_FOR(8 << 12, 50000);
BM_BOOST1DARRAY_FOR(8 << 15, 50000);
}
{
// boost regular 1D.
#define BM_BOOST1DVECTOR_FOR(objSize, entries) \
{ \
constexpr auto p = Parameters::forHistograms(objSize, entries); \
auto results = BM_BoostRegular1D<std::vector<int32_t>>(repetitions, p); \
printResultsCSV(file, "BoostRegular1DVector", p, results); \
printResultsCSV(std::cout, "BoostRegular1DVector", p, results); \
}
BM_BOOST1DVECTOR_FOR(8 << 0, 50000);
BM_BOOST1DVECTOR_FOR(8 << 3, 50000);
BM_BOOST1DVECTOR_FOR(8 << 6, 50000);
BM_BOOST1DVECTOR_FOR(8 << 9, 50000);
BM_BOOST1DVECTOR_FOR(8 << 12, 50000);
BM_BOOST1DVECTOR_FOR(8 << 15, 50000);
BM_BOOST1DVECTOR_FOR(8 << 18, 50000);
BM_BOOST1DVECTOR_FOR(8 << 21, 50000);
}
{
// boost regular 2D. We use a combination of template and macro to be able to use static storage (std::array) with different parameters.
#define BM_BOOST2DARRAY_FOR(objSize, arrSize, entries) \
{ \
constexpr auto p = Parameters::forHistograms(objSize, entries); \
auto results = BM_BoostRegular2D<std::array<int32_t, arrSize>>(repetitions, p); \
printResultsCSV(file, "BoostRegular2DArray", p, results); \
printResultsCSV(std::cout, "BoostRegular2DArray", p, results); \
}
BM_BOOST2DARRAY_FOR(8 << 0, 10, 50000);
BM_BOOST2DARRAY_FOR(8 << 3, 36, 50000);
BM_BOOST2DARRAY_FOR(8 << 6, 178, 50000);
BM_BOOST2DARRAY_FOR(8 << 9, 1156, 50000);
BM_BOOST2DARRAY_FOR(8 << 12, 8558, 50000);
BM_BOOST2DARRAY_FOR(8 << 15, 66564, 50000);
}
{
// boost regular 2D.
#define BM_BOOST2DVECTOR_FOR(objSize, entries) \
{ \
constexpr auto p = Parameters::forHistograms(objSize, entries); \
auto results = BM_BoostRegular2D<std::vector<int32_t>>(repetitions, p); \
printResultsCSV(file, "BoostRegular2DVector", p, results); \
printResultsCSV(std::cout, "BoostRegular2DVector", p, results); \
}
BM_BOOST2DVECTOR_FOR(8 << 0, 50000);
BM_BOOST2DVECTOR_FOR(8 << 3, 50000);
BM_BOOST2DVECTOR_FOR(8 << 6, 50000);
BM_BOOST2DVECTOR_FOR(8 << 9, 50000);
BM_BOOST2DVECTOR_FOR(8 << 12, 50000);
BM_BOOST2DVECTOR_FOR(8 << 15, 50000);
BM_BOOST2DVECTOR_FOR(8 << 18, 50000);
BM_BOOST2DVECTOR_FOR(8 << 21, 50000);
}
file.close();
return 0;
}