Skip to content

Commit 206227e

Browse files
committed
Improve RDF benchmark (suggestion of Enrico)
1 parent c3c1463 commit 206227e

File tree

1 file changed

+36
-51
lines changed

1 file changed

+36
-51
lines changed

root/io/io/TFile_RDFSnapshot.cxx

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,62 @@
66
#include "rootbench/RBConfig.h"
77

88

9-
static void BM_TFile_RDFSnapshot_ZLIB(benchmark::State &state) {
10-
ROOT::EnableImplicitMT();
11-
ROOT::RDF::RSnapshotOptions options;
12-
options.fCompressionAlgorithm = ROOT::ECompressionAlgorithm::kZLIB;
13-
9+
auto SetupRDF() {
1410
// We create an empty data frame
1511
ROOT::RDataFrame tdf(100000);
1612
// We now fill it with random numbers
1713
gRandom->SetSeed(1);
1814
auto tdf_1 = tdf.Define("rnd", []() { return gRandom->Gaus(); });
15+
return tdf_1;
16+
}
1917

20-
for (auto _ : state) {
21-
//And we write out the dataset on disk
22-
tdf_1.Snapshot("randomNumbers", "bench_data.root", "", options);
23-
}
18+
auto SetupRDFOptions(ROOT::ECompressionAlgorithm alg, int level) {
19+
ROOT::RDF::RSnapshotOptions options;
20+
options.fCompressionAlgorithm = alg;
21+
options.fCompressionLevel = level;
22+
return options;
2423
}
25-
BENCHMARK(BM_TFile_RDFSnapshot_ZLIB)->Unit(benchmark::kMicrosecond);
2624

2725

28-
static void BM_TFile_RDFSnapshot_LZ4(benchmark::State &state) {
29-
ROOT::EnableImplicitMT();
30-
ROOT::RDF::RSnapshotOptions options;
31-
options.fCompressionAlgorithm = ROOT::ECompressionAlgorithm::kLZ4;
26+
static void BM_TFile_RDFSnapshot_ZLIB(benchmark::State &state) {
27+
auto tdf = SetupRDF();
28+
auto options = SetupRDFOptions(ROOT::ECompressionAlgorithm::kZLIB, 1);
29+
for (auto _ : state) {
30+
//And we write out the dataset on disk
31+
tdf.Snapshot("randomNumbers", "bench_data.root", {"rnd"}, options);
32+
}
33+
}
34+
BENCHMARK(BM_TFile_RDFSnapshot_ZLIB)->Unit(benchmark::kMicrosecond);
3235

33-
// We create an empty data frame
34-
ROOT::RDataFrame tdf(100000);
35-
// We now fill it with random numbers
36-
gRandom->SetSeed(1);
37-
auto tdf_1 = tdf.Define("rnd", []() { return gRandom->Gaus(); });
3836

39-
for (auto _ : state) {
40-
//And we write out the dataset on disk
41-
tdf_1.Snapshot("randomNumbers", "bench_data.root", "", options);
42-
}
37+
static void BM_TFile_RDFSnapshot_LZ4(benchmark::State &state) {
38+
auto tdf = SetupRDF();
39+
auto options = SetupRDFOptions(ROOT::ECompressionAlgorithm::kLZ4, 4);
40+
for (auto _ : state) {
41+
//And we write out the dataset on disk
42+
tdf.Snapshot("randomNumbers", "bench_data.root", {"rnd"}, options);
43+
}
4344
}
4445
BENCHMARK(BM_TFile_RDFSnapshot_LZ4)->Unit(benchmark::kMicrosecond);
4546

4647

4748
static void BM_TFile_RDFSnapshot_LZMA (benchmark::State &state) {
48-
ROOT::EnableImplicitMT();
49-
ROOT::RDF::RSnapshotOptions options;
50-
options.fCompressionAlgorithm = ROOT::ECompressionAlgorithm::kLZMA;
51-
52-
// We create an empty data frame
53-
ROOT::RDataFrame tdf(100000);
54-
// We now fill it with random numbers
55-
gRandom->SetSeed(1);
56-
auto tdf_1 = tdf.Define("rnd", []() { return gRandom->Gaus(); });
57-
58-
for (auto _ : state) {
59-
//And we write out the dataset on disk
60-
tdf_1.Snapshot("randomNumbers", "bench_data.root", "", options);
61-
}
49+
auto tdf = SetupRDF();
50+
auto options = SetupRDFOptions(ROOT::ECompressionAlgorithm::kLZMA, 8);
51+
for (auto _ : state) {
52+
//And we write out the dataset on disk
53+
tdf.Snapshot("randomNumbers", "bench_data.root", {"rnd"}, options);
54+
}
6255
}
6356
BENCHMARK(BM_TFile_RDFSnapshot_LZMA)->Unit(benchmark::kMicrosecond);
6457

6558
static void BM_TFile_RDFSnapshot_ZSTD (benchmark::State &state) {
66-
ROOT::EnableImplicitMT();
67-
ROOT::RDF::RSnapshotOptions options;
68-
options.fCompressionAlgorithm = ROOT::ECompressionAlgorithm::kZSTD;
69-
70-
// We create an empty data frame
71-
ROOT::RDataFrame tdf(100000);
72-
// We now fill it with random numbers
73-
gRandom->SetSeed(1);
74-
auto tdf_1 = tdf.Define("rnd", []() { return gRandom->Gaus(); });
75-
76-
for (auto _ : state) {
77-
//And we write out the dataset on disk
78-
tdf_1.Snapshot("randomNumbers", "bench_data.root", "", options);
79-
}
59+
auto tdf = SetupRDF();
60+
auto options = SetupRDFOptions(ROOT::ECompressionAlgorithm::kZSTD, 6);
61+
for (auto _ : state) {
62+
//And we write out the dataset on disk
63+
tdf.Snapshot("randomNumbers", "bench_data.root", {"rnd"}, options);
64+
}
8065
}
8166
BENCHMARK(BM_TFile_RDFSnapshot_ZSTD)->Unit(benchmark::kMicrosecond);
8267

0 commit comments

Comments
 (0)