Skip to content

Commit db3affc

Browse files
committed
Fix io benchmarks to compress files properly
1 parent 641c626 commit db3affc

File tree

3 files changed

+51
-172
lines changed

3 files changed

+51
-172
lines changed
Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "TFile.h"
22
#include "TTree.h"
3+
#include "TSystem.h"
34

45
#include "benchmark/benchmark.h"
56
#include "rootbench/RBConfig.h"
@@ -20,38 +21,22 @@ static std::string GetAlgoName(int algo) {
2021
return "error";
2122
}
2223

23-
static void BM_ATLAS_Compress(benchmark::State &state, int algo) {
24-
TFile *oldfile = new TFile((RB::GetDataDir() + "/gg_data-zstd.root").c_str());
25-
TTree *oldtree = (TTree*)oldfile->Get("mini");
24+
static void BM_ATLAS_Decompress(benchmark::State &state, int algo) {
2625

2726
int comp_level = state.range(0);
28-
std::string filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root";
29-
30-
for (auto _ : state) {
31-
state.PauseTiming();
32-
33-
TFile *newfile = new TFile(filename.c_str(), "recreate");
34-
TTree *newtree = oldtree->CloneTree();
35-
newfile->SetCompressionAlgorithm(algo);
36-
newfile->SetCompressionLevel(comp_level);
27+
std::string comp_setting = std::to_string(algo * 100 + comp_level);
28+
std::string old_filename = (RB::GetDataDir() + "/gg_data-zstd.root").c_str();
29+
std::string new_filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root";
3730

38-
state.ResumeTiming();
39-
newfile->Write();
40-
state.PauseTiming();
41-
42-
state.counters["comp_size"] = newfile->GetBytesWritten();
43-
newfile->Close();
44-
45-
state.ResumeTiming();
46-
}
47-
}
31+
gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str());
4832

49-
static void BM_ATLAS_Decompress(benchmark::State &state, int algo) {
50-
int comp_level = state.range(0);
33+
TFile *newfile = new TFile(new_filename.c_str());
34+
state.counters["comp_size"] = newfile->GetSize();
35+
newfile->Close();
5136

52-
std::string filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root";
5337
for (auto _ : state) {
54-
TFile *hfile = new TFile(filename.c_str());
38+
39+
TFile *hfile = new TFile(new_filename.c_str());
5540
TTree *tree = (TTree*)hfile->Get("mini");
5641

5742
Int_t nevent = (Int_t)tree->GetEntries();
@@ -62,22 +47,15 @@ static void BM_ATLAS_Decompress(benchmark::State &state, int algo) {
6247
for (ev = 0; ev < nevent; ev++) {
6348
nb += tree->GetEntry(ev);
6449
}
50+
51+
hfile->Close();
52+
6553
}
66-
}
6754

68-
static void BM_ATLAS_Compress_ZLIB(benchmark::State &state) {
69-
BM_ATLAS_Compress(state, 1);
70-
}
71-
static void BM_ATLAS_Compress_LZMA(benchmark::State &state) {
72-
BM_ATLAS_Compress(state, 2);
73-
}
74-
static void BM_ATLAS_Compress_LZ4(benchmark::State &state) {
75-
BM_ATLAS_Compress(state, 4);
76-
}
77-
static void BM_ATLAS_Compress_ZSTD(benchmark::State &state) {
78-
BM_ATLAS_Compress(state, 5);
55+
gSystem->Exec(("rm -f " + new_filename).c_str());
7956
}
8057

58+
8159
static void BM_ATLAS_Decompress_ZLIB(benchmark::State &state) {
8260
BM_ATLAS_Decompress(state, 1);
8361
}
@@ -92,23 +70,6 @@ static void BM_ATLAS_Decompress_ZSTD(benchmark::State &state) {
9270
}
9371

9472

95-
BENCHMARK(BM_ATLAS_Compress_ZLIB)
96-
->Arg(1)->Arg(6)->Arg(9)
97-
->Unit(benchmark::kMillisecond)->Iterations(5);
98-
99-
BENCHMARK(BM_ATLAS_Compress_LZMA)
100-
->Arg(1)->Arg(6)->Arg(9)
101-
->Unit(benchmark::kMillisecond)->Iterations(5);
102-
103-
BENCHMARK(BM_ATLAS_Compress_LZ4)
104-
->Arg(1)->Arg(6)->Arg(9)
105-
->Unit(benchmark::kMillisecond)->Iterations(5);
106-
107-
BENCHMARK(BM_ATLAS_Compress_ZSTD)
108-
->Arg(1)->Arg(6)->Arg(9)
109-
->Unit(benchmark::kMillisecond)->Iterations(5);
110-
111-
11273
BENCHMARK(BM_ATLAS_Decompress_ZLIB)
11374
->Arg(1)->Arg(6)->Arg(9)
11475
->Unit(benchmark::kMillisecond)->Iterations(5);
@@ -126,4 +87,4 @@ BENCHMARK(BM_ATLAS_Decompress_ZSTD)
12687
->Unit(benchmark::kMillisecond)->Iterations(5);
12788

12889

129-
BENCHMARK_MAIN();
90+
BENCHMARK_MAIN();
Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "TFile.h"
22
#include "TTree.h"
3+
#include "TSystem.h"
34

45
#include "benchmark/benchmark.h"
56
#include "rootbench/RBConfig.h"
@@ -20,42 +21,22 @@ static std::string GetAlgoName(int algo) {
2021
return "error";
2122
}
2223

23-
static void BM_LHCb_Compress(benchmark::State &state, int algo) {
24-
TFile *oldfile = new TFile((RB::GetDataDir() + "/lhcb_B2ppKK2011_md_noPIDstrip.root").c_str());
25-
TTree *oldtree1 = (TTree*)oldfile->Get("TupleB2ppKK/DecayTree");
26-
TTree *oldtree2 = (TTree*)oldfile->Get("TupleB2ppKPi/DecayTree");
27-
TTree *oldtree3 = (TTree*)oldfile->Get("TupleB2ppPiPi/DecayTree");
24+
static void BM_LHCb_Decompress(benchmark::State &state, int algo) {
2825

2926
int comp_level = state.range(0);
30-
std::string filename = "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root";
31-
32-
for (auto _ : state) {
33-
state.PauseTiming();
34-
35-
TFile *newfile = new TFile(filename.c_str(), "recreate");
36-
TTree *newtree1 = oldtree1->CloneTree();
37-
TTree *newtree2 = oldtree2->CloneTree();
38-
TTree *newtree3 = oldtree3->CloneTree();
39-
newfile->SetCompressionAlgorithm(algo);
40-
newfile->SetCompressionLevel(comp_level);
27+
std::string comp_setting = std::to_string(algo * 100 + comp_level);
28+
std::string old_filename = (RB::GetDataDir() + "/lhcb_B2ppKK2011_md_noPIDstrip.root").c_str();
29+
std::string new_filename = "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root";
4130

42-
state.ResumeTiming();
43-
newfile->Write();
44-
state.PauseTiming();
31+
gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str());
4532

46-
state.counters["comp_size"] = newfile->GetBytesWritten();
47-
newfile->Close();
33+
TFile *newfile = new TFile(new_filename.c_str());
34+
state.counters["comp_size"] = newfile->GetSize();
35+
newfile->Close();
4836

49-
state.ResumeTiming();
50-
}
51-
}
52-
53-
static void BM_LHCb_Decompress(benchmark::State &state, int algo) {
54-
int comp_level = state.range(0);
55-
56-
std::string filename = "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root";
5737
for (auto _ : state) {
58-
TFile *hfile = new TFile(filename.c_str());
38+
39+
TFile *hfile = new TFile(new_filename.c_str());
5940
TTree *tree1 = (TTree*)hfile->Get("TupleB2ppKK/DecayTree");
6041
TTree *tree2 = (TTree*)hfile->Get("TupleB2ppKPi/DecayTree");
6142
TTree *tree3 = (TTree*)hfile->Get("TupleB2ppPiPi/DecayTree");
@@ -78,22 +59,15 @@ static void BM_LHCb_Decompress(benchmark::State &state, int algo) {
7859
for (ev = 0; ev < nevent3; ev++) {
7960
nb += tree3->GetEntry(ev);
8061
}
62+
63+
hfile->Close();
64+
8165
}
82-
}
8366

84-
static void BM_LHCb_Compress_ZLIB(benchmark::State &state) {
85-
BM_LHCb_Compress(state, 1);
86-
}
87-
static void BM_LHCb_Compress_LZMA(benchmark::State &state) {
88-
BM_LHCb_Compress(state, 2);
89-
}
90-
static void BM_LHCb_Compress_LZ4(benchmark::State &state) {
91-
BM_LHCb_Compress(state, 4);
92-
}
93-
static void BM_LHCb_Compress_ZSTD(benchmark::State &state) {
94-
BM_LHCb_Compress(state, 5);
67+
gSystem->Exec(("rm -f " + new_filename).c_str());
9568
}
9669

70+
9771
static void BM_LHCb_Decompress_ZLIB(benchmark::State &state) {
9872
BM_LHCb_Decompress(state, 1);
9973
}
@@ -108,23 +82,6 @@ static void BM_LHCb_Decompress_ZSTD(benchmark::State &state) {
10882
}
10983

11084

111-
BENCHMARK(BM_LHCb_Compress_ZLIB)
112-
->Arg(1)->Arg(6)->Arg(9)
113-
->Unit(benchmark::kMillisecond)->Iterations(5);
114-
115-
BENCHMARK(BM_LHCb_Compress_LZMA)
116-
->Arg(1)->Arg(6)->Arg(9)
117-
->Unit(benchmark::kMillisecond)->Iterations(5);
118-
119-
BENCHMARK(BM_LHCb_Compress_LZ4)
120-
->Arg(1)->Arg(6)->Arg(9)
121-
->Unit(benchmark::kMillisecond)->Iterations(5);
122-
123-
BENCHMARK(BM_LHCb_Compress_ZSTD)
124-
->Arg(1)->Arg(6)->Arg(9)
125-
->Unit(benchmark::kMillisecond)->Iterations(5);
126-
127-
12885
BENCHMARK(BM_LHCb_Decompress_ZLIB)
12986
->Arg(1)->Arg(6)->Arg(9)
13087
->Unit(benchmark::kMillisecond)->Iterations(5);
@@ -142,4 +99,4 @@ BENCHMARK(BM_LHCb_Decompress_ZSTD)
14299
->Unit(benchmark::kMillisecond)->Iterations(5);
143100

144101

145-
BENCHMARK_MAIN();
102+
BENCHMARK_MAIN();
Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "TFile.h"
22
#include "TTree.h"
3+
#include "TSystem.h"
34

45
#include "benchmark/benchmark.h"
56
#include "rootbench/RBConfig.h"
@@ -20,38 +21,22 @@ static std::string GetAlgoName(int algo) {
2021
return "error";
2122
}
2223

23-
static void BM_NanoAOD_Compress(benchmark::State &state, int algo) {
24-
TFile *oldfile = new TFile((RB::GetDataDir() + "/Run2012B_DoubleMuParked.root").c_str());
25-
TTree *oldtree = (TTree*)oldfile->Get("Events");
24+
static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) {
2625

2726
int comp_level = state.range(0);
28-
std::string filename = "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root";
29-
30-
for (auto _ : state) {
31-
state.PauseTiming();
32-
33-
TFile *newfile = new TFile(filename.c_str(), "recreate");
34-
TTree *newtree = oldtree->CloneTree();
35-
newfile->SetCompressionAlgorithm(algo);
36-
newfile->SetCompressionLevel(comp_level);
27+
std::string comp_setting = std::to_string(algo * 100 + comp_level);
28+
std::string old_filename = (RB::GetDataDir() + "/Run2012B_DoubleMuParked.root").c_str();
29+
std::string new_filename = "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root";
3730

38-
state.ResumeTiming();
39-
newfile->Write();
40-
state.PauseTiming();
31+
gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str());
4132

42-
state.counters["comp_size"] = newfile->GetBytesWritten();
43-
newfile->Close();
33+
TFile *newfile = new TFile(new_filename.c_str());
34+
state.counters["comp_size"] = newfile->GetSize();
35+
newfile->Close();
4436

45-
state.ResumeTiming();
46-
}
47-
}
48-
49-
static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) {
50-
int comp_level = state.range(0);
51-
52-
std::string filename = "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root";
5337
for (auto _ : state) {
54-
TFile *hfile = new TFile(filename.c_str());
38+
39+
TFile *hfile = new TFile(new_filename.c_str());
5540
TTree *tree = (TTree*)hfile->Get("Events");
5641

5742
Int_t nevent = (Int_t)tree->GetEntries();
@@ -62,22 +47,15 @@ static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) {
6247
for (ev = 0; ev < nevent; ev++) {
6348
nb += tree->GetEntry(ev);
6449
}
50+
51+
hfile->Close();
52+
6553
}
66-
}
6754

68-
static void BM_NanoAOD_Compress_ZLIB(benchmark::State &state) {
69-
BM_NanoAOD_Compress(state, 1);
70-
}
71-
static void BM_NanoAOD_Compress_LZMA(benchmark::State &state) {
72-
BM_NanoAOD_Compress(state, 2);
73-
}
74-
static void BM_NanoAOD_Compress_LZ4(benchmark::State &state) {
75-
BM_NanoAOD_Compress(state, 4);
76-
}
77-
static void BM_NanoAOD_Compress_ZSTD(benchmark::State &state) {
78-
BM_NanoAOD_Compress(state, 5);
55+
gSystem->Exec(("rm -f " + new_filename).c_str());
7956
}
8057

58+
8159
static void BM_NanoAOD_Decompress_ZLIB(benchmark::State &state) {
8260
BM_NanoAOD_Decompress(state, 1);
8361
}
@@ -92,23 +70,6 @@ static void BM_NanoAOD_Decompress_ZSTD(benchmark::State &state) {
9270
}
9371

9472

95-
BENCHMARK(BM_NanoAOD_Compress_ZLIB)
96-
->Arg(1)->Arg(6)->Arg(9)
97-
->Unit(benchmark::kMillisecond)->Iterations(5);
98-
99-
BENCHMARK(BM_NanoAOD_Compress_LZMA)
100-
->Arg(1)->Arg(6)->Arg(9)
101-
->Unit(benchmark::kMillisecond)->Iterations(5);
102-
103-
BENCHMARK(BM_NanoAOD_Compress_LZ4)
104-
->Arg(1)->Arg(6)->Arg(9)
105-
->Unit(benchmark::kMillisecond)->Iterations(5);
106-
107-
BENCHMARK(BM_NanoAOD_Compress_ZSTD)
108-
->Arg(1)->Arg(6)->Arg(9)
109-
->Unit(benchmark::kMillisecond)->Iterations(5);
110-
111-
11273
BENCHMARK(BM_NanoAOD_Decompress_ZLIB)
11374
->Arg(1)->Arg(6)->Arg(9)
11475
->Unit(benchmark::kMillisecond)->Iterations(5);
@@ -126,4 +87,4 @@ BENCHMARK(BM_NanoAOD_Decompress_ZSTD)
12687
->Unit(benchmark::kMillisecond)->Iterations(5);
12788

12889

129-
BENCHMARK_MAIN();
90+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)