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+
9771static 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-
12885BENCHMARK (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 ();
0 commit comments