From 030bcd01a18ebc762d80ca363697a26042873427 Mon Sep 17 00:00:00 2001 From: kamahori Date: Mon, 17 Aug 2020 08:27:01 +0000 Subject: [PATCH 1/6] Fix io benchmarks to compress files properly --- root/io/io/TFile_ATLAS_Benchmarks.cxx | 73 ++++++----------------- root/io/io/TFile_LHCb_Benchmarks.cxx | 77 ++++++------------------- root/io/io/TFile_NanoAOD_Benchmarks.cxx | 71 +++++------------------ 3 files changed, 50 insertions(+), 171 deletions(-) diff --git a/root/io/io/TFile_ATLAS_Benchmarks.cxx b/root/io/io/TFile_ATLAS_Benchmarks.cxx index d7c94d93..841baffa 100644 --- a/root/io/io/TFile_ATLAS_Benchmarks.cxx +++ b/root/io/io/TFile_ATLAS_Benchmarks.cxx @@ -1,5 +1,6 @@ #include "TFile.h" #include "TTree.h" +#include "TSystem.h" #include "benchmark/benchmark.h" #include "rootbench/RBConfig.h" @@ -20,38 +21,22 @@ static std::string GetAlgoName(int algo) { return "error"; } -static void BM_ATLAS_Compress(benchmark::State &state, int algo) { - TFile *oldfile = new TFile((RB::GetDataDir() + "/gg_data-zstd.root").c_str()); - TTree *oldtree = (TTree*)oldfile->Get("mini"); +static void BM_ATLAS_Decompress(benchmark::State &state, int algo) { int comp_level = state.range(0); - std::string filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root"; - - for (auto _ : state) { - state.PauseTiming(); - - TFile *newfile = new TFile(filename.c_str(), "recreate"); - TTree *newtree = oldtree->CloneTree(); - newfile->SetCompressionAlgorithm(algo); - newfile->SetCompressionLevel(comp_level); + std::string comp_setting = std::to_string(algo * 100 + comp_level); + std::string old_filename = (RB::GetDataDir() + "/gg_data-zstd.root").c_str(); + std::string new_filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root"; - state.ResumeTiming(); - newfile->Write(); - state.PauseTiming(); - - state.counters["comp_size"] = newfile->GetBytesWritten(); - newfile->Close(); - - state.ResumeTiming(); - } -} + gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); -static void BM_ATLAS_Decompress(benchmark::State &state, int algo) { - int comp_level = state.range(0); + TFile *newfile = new TFile(new_filename.c_str()); + state.counters["comp_size"] = newfile->GetSize(); + newfile->Close(); - std::string filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root"; for (auto _ : state) { - TFile *hfile = new TFile(filename.c_str()); + + TFile *hfile = new TFile(new_filename.c_str()); TTree *tree = (TTree*)hfile->Get("mini"); Int_t nevent = (Int_t)tree->GetEntries(); @@ -62,22 +47,15 @@ static void BM_ATLAS_Decompress(benchmark::State &state, int algo) { for (ev = 0; ev < nevent; ev++) { nb += tree->GetEntry(ev); } + + hfile->Close(); + } -} -static void BM_ATLAS_Compress_ZLIB(benchmark::State &state) { - BM_ATLAS_Compress(state, 1); -} -static void BM_ATLAS_Compress_LZMA(benchmark::State &state) { - BM_ATLAS_Compress(state, 2); -} -static void BM_ATLAS_Compress_LZ4(benchmark::State &state) { - BM_ATLAS_Compress(state, 4); -} -static void BM_ATLAS_Compress_ZSTD(benchmark::State &state) { - BM_ATLAS_Compress(state, 5); + gSystem->Exec(("rm -f " + new_filename).c_str()); } + static void BM_ATLAS_Decompress_ZLIB(benchmark::State &state) { BM_ATLAS_Decompress(state, 1); } @@ -92,23 +70,6 @@ static void BM_ATLAS_Decompress_ZSTD(benchmark::State &state) { } -BENCHMARK(BM_ATLAS_Compress_ZLIB) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - -BENCHMARK(BM_ATLAS_Compress_LZMA) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - -BENCHMARK(BM_ATLAS_Compress_LZ4) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - -BENCHMARK(BM_ATLAS_Compress_ZSTD) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - - BENCHMARK(BM_ATLAS_Decompress_ZLIB) ->Arg(1)->Arg(6)->Arg(9) ->Unit(benchmark::kMillisecond)->Iterations(5); @@ -126,4 +87,4 @@ BENCHMARK(BM_ATLAS_Decompress_ZSTD) ->Unit(benchmark::kMillisecond)->Iterations(5); -BENCHMARK_MAIN(); \ No newline at end of file +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/root/io/io/TFile_LHCb_Benchmarks.cxx b/root/io/io/TFile_LHCb_Benchmarks.cxx index 5e1e026c..3fa13e3b 100644 --- a/root/io/io/TFile_LHCb_Benchmarks.cxx +++ b/root/io/io/TFile_LHCb_Benchmarks.cxx @@ -1,5 +1,6 @@ #include "TFile.h" #include "TTree.h" +#include "TSystem.h" #include "benchmark/benchmark.h" #include "rootbench/RBConfig.h" @@ -20,42 +21,22 @@ static std::string GetAlgoName(int algo) { return "error"; } -static void BM_LHCb_Compress(benchmark::State &state, int algo) { - TFile *oldfile = new TFile((RB::GetDataDir() + "/lhcb_B2ppKK2011_md_noPIDstrip.root").c_str()); - TTree *oldtree1 = (TTree*)oldfile->Get("TupleB2ppKK/DecayTree"); - TTree *oldtree2 = (TTree*)oldfile->Get("TupleB2ppKPi/DecayTree"); - TTree *oldtree3 = (TTree*)oldfile->Get("TupleB2ppPiPi/DecayTree"); +static void BM_LHCb_Decompress(benchmark::State &state, int algo) { int comp_level = state.range(0); - std::string filename = "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root"; - - for (auto _ : state) { - state.PauseTiming(); - - TFile *newfile = new TFile(filename.c_str(), "recreate"); - TTree *newtree1 = oldtree1->CloneTree(); - TTree *newtree2 = oldtree2->CloneTree(); - TTree *newtree3 = oldtree3->CloneTree(); - newfile->SetCompressionAlgorithm(algo); - newfile->SetCompressionLevel(comp_level); + std::string comp_setting = std::to_string(algo * 100 + comp_level); + std::string old_filename = (RB::GetDataDir() + "/lhcb_B2ppKK2011_md_noPIDstrip.root").c_str(); + std::string new_filename = "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root"; - state.ResumeTiming(); - newfile->Write(); - state.PauseTiming(); + gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); - state.counters["comp_size"] = newfile->GetBytesWritten(); - newfile->Close(); + TFile *newfile = new TFile(new_filename.c_str()); + state.counters["comp_size"] = newfile->GetSize(); + newfile->Close(); - state.ResumeTiming(); - } -} - -static void BM_LHCb_Decompress(benchmark::State &state, int algo) { - int comp_level = state.range(0); - - std::string filename = "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root"; for (auto _ : state) { - TFile *hfile = new TFile(filename.c_str()); + + TFile *hfile = new TFile(new_filename.c_str()); TTree *tree1 = (TTree*)hfile->Get("TupleB2ppKK/DecayTree"); TTree *tree2 = (TTree*)hfile->Get("TupleB2ppKPi/DecayTree"); TTree *tree3 = (TTree*)hfile->Get("TupleB2ppPiPi/DecayTree"); @@ -78,22 +59,15 @@ static void BM_LHCb_Decompress(benchmark::State &state, int algo) { for (ev = 0; ev < nevent3; ev++) { nb += tree3->GetEntry(ev); } + + hfile->Close(); + } -} -static void BM_LHCb_Compress_ZLIB(benchmark::State &state) { - BM_LHCb_Compress(state, 1); -} -static void BM_LHCb_Compress_LZMA(benchmark::State &state) { - BM_LHCb_Compress(state, 2); -} -static void BM_LHCb_Compress_LZ4(benchmark::State &state) { - BM_LHCb_Compress(state, 4); -} -static void BM_LHCb_Compress_ZSTD(benchmark::State &state) { - BM_LHCb_Compress(state, 5); + gSystem->Exec(("rm -f " + new_filename).c_str()); } + static void BM_LHCb_Decompress_ZLIB(benchmark::State &state) { BM_LHCb_Decompress(state, 1); } @@ -108,23 +82,6 @@ static void BM_LHCb_Decompress_ZSTD(benchmark::State &state) { } -BENCHMARK(BM_LHCb_Compress_ZLIB) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - -BENCHMARK(BM_LHCb_Compress_LZMA) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - -BENCHMARK(BM_LHCb_Compress_LZ4) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - -BENCHMARK(BM_LHCb_Compress_ZSTD) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - - BENCHMARK(BM_LHCb_Decompress_ZLIB) ->Arg(1)->Arg(6)->Arg(9) ->Unit(benchmark::kMillisecond)->Iterations(5); @@ -142,4 +99,4 @@ BENCHMARK(BM_LHCb_Decompress_ZSTD) ->Unit(benchmark::kMillisecond)->Iterations(5); -BENCHMARK_MAIN(); \ No newline at end of file +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/root/io/io/TFile_NanoAOD_Benchmarks.cxx b/root/io/io/TFile_NanoAOD_Benchmarks.cxx index 52671578..f6fc4d5c 100644 --- a/root/io/io/TFile_NanoAOD_Benchmarks.cxx +++ b/root/io/io/TFile_NanoAOD_Benchmarks.cxx @@ -1,5 +1,6 @@ #include "TFile.h" #include "TTree.h" +#include "TSystem.h" #include "benchmark/benchmark.h" #include "rootbench/RBConfig.h" @@ -20,38 +21,22 @@ static std::string GetAlgoName(int algo) { return "error"; } -static void BM_NanoAOD_Compress(benchmark::State &state, int algo) { - TFile *oldfile = new TFile((RB::GetDataDir() + "/Run2012B_DoubleMuParked.root").c_str()); - TTree *oldtree = (TTree*)oldfile->Get("Events"); +static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) { int comp_level = state.range(0); - std::string filename = "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root"; - - for (auto _ : state) { - state.PauseTiming(); - - TFile *newfile = new TFile(filename.c_str(), "recreate"); - TTree *newtree = oldtree->CloneTree(); - newfile->SetCompressionAlgorithm(algo); - newfile->SetCompressionLevel(comp_level); + std::string comp_setting = std::to_string(algo * 100 + comp_level); + std::string old_filename = (RB::GetDataDir() + "/Run2012B_DoubleMuParked.root").c_str(); + std::string new_filename = "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root"; - state.ResumeTiming(); - newfile->Write(); - state.PauseTiming(); + gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); - state.counters["comp_size"] = newfile->GetBytesWritten(); - newfile->Close(); + TFile *newfile = new TFile(new_filename.c_str()); + state.counters["comp_size"] = newfile->GetSize(); + newfile->Close(); - state.ResumeTiming(); - } -} - -static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) { - int comp_level = state.range(0); - - std::string filename = "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root"; for (auto _ : state) { - TFile *hfile = new TFile(filename.c_str()); + + TFile *hfile = new TFile(new_filename.c_str()); TTree *tree = (TTree*)hfile->Get("Events"); Int_t nevent = (Int_t)tree->GetEntries(); @@ -62,22 +47,15 @@ static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) { for (ev = 0; ev < nevent; ev++) { nb += tree->GetEntry(ev); } + + hfile->Close(); + } -} -static void BM_NanoAOD_Compress_ZLIB(benchmark::State &state) { - BM_NanoAOD_Compress(state, 1); -} -static void BM_NanoAOD_Compress_LZMA(benchmark::State &state) { - BM_NanoAOD_Compress(state, 2); -} -static void BM_NanoAOD_Compress_LZ4(benchmark::State &state) { - BM_NanoAOD_Compress(state, 4); -} -static void BM_NanoAOD_Compress_ZSTD(benchmark::State &state) { - BM_NanoAOD_Compress(state, 5); + gSystem->Exec(("rm -f " + new_filename).c_str()); } + static void BM_NanoAOD_Decompress_ZLIB(benchmark::State &state) { BM_NanoAOD_Decompress(state, 1); } @@ -92,23 +70,6 @@ static void BM_NanoAOD_Decompress_ZSTD(benchmark::State &state) { } -BENCHMARK(BM_NanoAOD_Compress_ZLIB) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - -BENCHMARK(BM_NanoAOD_Compress_LZMA) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - -BENCHMARK(BM_NanoAOD_Compress_LZ4) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - -BENCHMARK(BM_NanoAOD_Compress_ZSTD) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); - - BENCHMARK(BM_NanoAOD_Decompress_ZLIB) ->Arg(1)->Arg(6)->Arg(9) ->Unit(benchmark::kMillisecond)->Iterations(5); From 4f0ae34a305ca4dffaf5c2dec983ecd44e509f7b Mon Sep 17 00:00:00 2001 From: kamahori Date: Wed, 19 Aug 2020 12:13:26 +0000 Subject: [PATCH 2/6] Change files and number of iterations to save time --- root/io/io/CMakeLists.txt | 33 ++++++------- root/io/io/TFile_ATLAS_Benchmarks.cxx | 65 ++++++++++++++++++------- root/io/io/TFile_LHCb_Benchmarks.cxx | 8 +-- root/io/io/TFile_NanoAOD_Benchmarks.cxx | 10 ++-- 4 files changed, 72 insertions(+), 44 deletions(-) diff --git a/root/io/io/CMakeLists.txt b/root/io/io/CMakeLists.txt index 3c178a81..9464659d 100644 --- a/root/io/io/CMakeLists.txt +++ b/root/io/io/CMakeLists.txt @@ -21,22 +21,21 @@ if(rootbench-datafiles) # DOWNLOAD_DATAFILES Event0-sample.root) #endif() - # FIXME: too long benchmarks, needs to be optimised - #RB_ADD_GBENCHMARK(CompressionBenchmarks_LHCb - # TFile_LHCb_Benchmarks.cxx - # LABEL short - # LIBRARIES Core RIO - # DOWNLOAD_DATAFILES lhcb_B2ppKK2011_md_noPIDstrip.root) + RB_ADD_GBENCHMARK(CompressionBenchmarks_LHCb + TFile_LHCb_Benchmarks.cxx + LABEL short + LIBRARIES Core RIO + DOWNLOAD_DATAFILES lhcb_B2ppKK2011_md_noPIDstrip.root) - #RB_ADD_GBENCHMARK(CompressionBenchmarks_NanoAOD - # TFile_NanoAOD_Benchmarks.cxx - # LABEL short - # LIBRARIES Core RIO - # DOWNLOAD_DATAFILES Run2012B_DoubleMuParked.root) + RB_ADD_GBENCHMARK(CompressionBenchmarks_NanoAOD + TFile_NanoAOD_Benchmarks.cxx + LABEL short + LIBRARIES Core RIO + DOWNLOAD_DATAFILES Run2012B_DoubleElectron.root) - #RB_ADD_GBENCHMARK(CompressionBenchmarks_ATLAS - # TFile_ATLAS_Benchmarks.cxx - # LABEL short - # LIBRARIES Core RIO - # DOWNLOAD_DATAFILES gg_data-zstd.root) -endif() + RB_ADD_GBENCHMARK(CompressionBenchmarks_ATLAS + TFile_ATLAS_Benchmarks.cxx + LABEL short + LIBRARIES Core RIO + DOWNLOAD_DATAFILES atlasopendata_mc_117050.ttbar_lep.root atlasopendata_DataMuons.root) +endif() \ No newline at end of file diff --git a/root/io/io/TFile_ATLAS_Benchmarks.cxx b/root/io/io/TFile_ATLAS_Benchmarks.cxx index 841baffa..685ba080 100644 --- a/root/io/io/TFile_ATLAS_Benchmarks.cxx +++ b/root/io/io/TFile_ATLAS_Benchmarks.cxx @@ -21,11 +21,11 @@ static std::string GetAlgoName(int algo) { return "error"; } -static void BM_ATLAS_Decompress(benchmark::State &state, int algo) { +static void BM_ATLAS_Decompress(benchmark::State &state, int algo, std::string filename) { int comp_level = state.range(0); std::string comp_setting = std::to_string(algo * 100 + comp_level); - std::string old_filename = (RB::GetDataDir() + "/gg_data-zstd.root").c_str(); + std::string old_filename = (RB::GetDataDir() + "/" + filename + ".root").c_str(); std::string new_filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root"; gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); @@ -56,35 +56,64 @@ static void BM_ATLAS_Decompress(benchmark::State &state, int algo) { } -static void BM_ATLAS_Decompress_ZLIB(benchmark::State &state) { - BM_ATLAS_Decompress(state, 1); +static void BM_ATLAS_Decompress_Real_ZLIB(benchmark::State &state) { + BM_ATLAS_Decompress(state, 1, "atlasopendata_DataMuons"); } -static void BM_ATLAS_Decompress_LZMA(benchmark::State &state) { - BM_ATLAS_Decompress(state, 2); +static void BM_ATLAS_Decompress_Real_LZMA(benchmark::State &state) { + BM_ATLAS_Decompress(state, 2, "atlasopendata_DataMuons"); } -static void BM_ATLAS_Decompress_LZ4(benchmark::State &state) { - BM_ATLAS_Decompress(state, 4); +static void BM_ATLAS_Decompress_Real_LZ4(benchmark::State &state) { + BM_ATLAS_Decompress(state, 4, "atlasopendata_DataMuons"); } -static void BM_ATLAS_Decompress_ZSTD(benchmark::State &state) { - BM_ATLAS_Decompress(state, 5); +static void BM_ATLAS_Decompress_Real_ZSTD(benchmark::State &state) { + BM_ATLAS_Decompress(state, 5, "atlasopendata_DataMuons"); } +BENCHMARK(BM_ATLAS_Decompress_Real_ZLIB) +->Arg(1)->Arg(6)->Arg(9) +->Unit(benchmark::kMillisecond)->Iterations(3); + +BENCHMARK(BM_ATLAS_Decompress_Real_LZMA) +->Arg(1)->Arg(6)->Arg(9) +->Unit(benchmark::kMillisecond)->Iterations(3); + +BENCHMARK(BM_ATLAS_Decompress_Real_LZ4) +->Arg(1)->Arg(6)->Arg(9) +->Unit(benchmark::kMillisecond)->Iterations(3); + +BENCHMARK(BM_ATLAS_Decompress_Real_ZSTD) +->Arg(1)->Arg(6)->Arg(9) +->Unit(benchmark::kMillisecond)->Iterations(3); + + +static void BM_ATLAS_Decompress_MC_ZLIB(benchmark::State &state) { + BM_ATLAS_Decompress(state, 1, "atlasopendata_mc_117050.ttbar_lep"); +} +static void BM_ATLAS_Decompress_MC_LZMA(benchmark::State &state) { + BM_ATLAS_Decompress(state, 2, "atlasopendata_mc_117050.ttbar_lep"); +} +static void BM_ATLAS_Decompress_MC_LZ4(benchmark::State &state) { + BM_ATLAS_Decompress(state, 4, "atlasopendata_mc_117050.ttbar_lep"); +} +static void BM_ATLAS_Decompress_MC_ZSTD(benchmark::State &state) { + BM_ATLAS_Decompress(state, 5, "atlasopendata_mc_117050.ttbar_lep"); +} -BENCHMARK(BM_ATLAS_Decompress_ZLIB) +BENCHMARK(BM_ATLAS_Decompress_MC_ZLIB) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); -BENCHMARK(BM_ATLAS_Decompress_LZMA) +BENCHMARK(BM_ATLAS_Decompress_MC_LZMA) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); -BENCHMARK(BM_ATLAS_Decompress_LZ4) +BENCHMARK(BM_ATLAS_Decompress_MC_LZ4) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); -BENCHMARK(BM_ATLAS_Decompress_ZSTD) +BENCHMARK(BM_ATLAS_Decompress_MC_ZSTD) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); BENCHMARK_MAIN(); \ No newline at end of file diff --git a/root/io/io/TFile_LHCb_Benchmarks.cxx b/root/io/io/TFile_LHCb_Benchmarks.cxx index 3fa13e3b..5fe2fe6a 100644 --- a/root/io/io/TFile_LHCb_Benchmarks.cxx +++ b/root/io/io/TFile_LHCb_Benchmarks.cxx @@ -84,19 +84,19 @@ static void BM_LHCb_Decompress_ZSTD(benchmark::State &state) { BENCHMARK(BM_LHCb_Decompress_ZLIB) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); BENCHMARK(BM_LHCb_Decompress_LZMA) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); BENCHMARK(BM_LHCb_Decompress_LZ4) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); BENCHMARK(BM_LHCb_Decompress_ZSTD) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); BENCHMARK_MAIN(); \ No newline at end of file diff --git a/root/io/io/TFile_NanoAOD_Benchmarks.cxx b/root/io/io/TFile_NanoAOD_Benchmarks.cxx index f6fc4d5c..2f093c19 100644 --- a/root/io/io/TFile_NanoAOD_Benchmarks.cxx +++ b/root/io/io/TFile_NanoAOD_Benchmarks.cxx @@ -25,7 +25,7 @@ static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) { int comp_level = state.range(0); std::string comp_setting = std::to_string(algo * 100 + comp_level); - std::string old_filename = (RB::GetDataDir() + "/Run2012B_DoubleMuParked.root").c_str(); + std::string old_filename = (RB::GetDataDir() + "/Run2012B_DoubleElectron.root").c_str(); std::string new_filename = "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root"; gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); @@ -72,19 +72,19 @@ static void BM_NanoAOD_Decompress_ZSTD(benchmark::State &state) { BENCHMARK(BM_NanoAOD_Decompress_ZLIB) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); BENCHMARK(BM_NanoAOD_Decompress_LZMA) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); BENCHMARK(BM_NanoAOD_Decompress_LZ4) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); BENCHMARK(BM_NanoAOD_Decompress_ZSTD) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(5); +->Unit(benchmark::kMillisecond)->Iterations(3); BENCHMARK_MAIN(); From 8b4a43919589a8579472300154b246ba9be9c6d4 Mon Sep 17 00:00:00 2001 From: kamahori Date: Thu, 20 Aug 2020 12:10:52 +0000 Subject: [PATCH 3/6] Use RB::GetTempFs() --- root/io/io/TFile_ATLAS_Benchmarks.cxx | 2 +- root/io/io/TFile_LHCb_Benchmarks.cxx | 2 +- root/io/io/TFile_NanoAOD_Benchmarks.cxx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/root/io/io/TFile_ATLAS_Benchmarks.cxx b/root/io/io/TFile_ATLAS_Benchmarks.cxx index 685ba080..e8b542c4 100644 --- a/root/io/io/TFile_ATLAS_Benchmarks.cxx +++ b/root/io/io/TFile_ATLAS_Benchmarks.cxx @@ -26,7 +26,7 @@ static void BM_ATLAS_Decompress(benchmark::State &state, int algo, std::string f int comp_level = state.range(0); std::string comp_setting = std::to_string(algo * 100 + comp_level); std::string old_filename = (RB::GetDataDir() + "/" + filename + ".root").c_str(); - std::string new_filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root"; + std::string new_filename = (RB::GetTempFs() + "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root").c_str(); gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); diff --git a/root/io/io/TFile_LHCb_Benchmarks.cxx b/root/io/io/TFile_LHCb_Benchmarks.cxx index 5fe2fe6a..7be6aca2 100644 --- a/root/io/io/TFile_LHCb_Benchmarks.cxx +++ b/root/io/io/TFile_LHCb_Benchmarks.cxx @@ -26,7 +26,7 @@ static void BM_LHCb_Decompress(benchmark::State &state, int algo) { int comp_level = state.range(0); std::string comp_setting = std::to_string(algo * 100 + comp_level); std::string old_filename = (RB::GetDataDir() + "/lhcb_B2ppKK2011_md_noPIDstrip.root").c_str(); - std::string new_filename = "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root"; + std::string new_filename = (RB::GetTempFs() + "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root"); gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); diff --git a/root/io/io/TFile_NanoAOD_Benchmarks.cxx b/root/io/io/TFile_NanoAOD_Benchmarks.cxx index 2f093c19..00557822 100644 --- a/root/io/io/TFile_NanoAOD_Benchmarks.cxx +++ b/root/io/io/TFile_NanoAOD_Benchmarks.cxx @@ -26,7 +26,7 @@ static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) { int comp_level = state.range(0); std::string comp_setting = std::to_string(algo * 100 + comp_level); std::string old_filename = (RB::GetDataDir() + "/Run2012B_DoubleElectron.root").c_str(); - std::string new_filename = "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root"; + std::string new_filename = (RB::GetTempFs() + "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root").c_str(); gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); From fbc7ffca48de9ef58f78022425e7494db278dbb9 Mon Sep 17 00:00:00 2001 From: kamahori Date: Mon, 31 Aug 2020 14:35:38 +0000 Subject: [PATCH 4/6] Remove ATLAS Real BM and reduce iterations to 2 --- root/io/io/CMakeLists.txt | 2 +- root/io/io/TFile_ATLAS_Benchmarks.cxx | 41 +++++---------------------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/root/io/io/CMakeLists.txt b/root/io/io/CMakeLists.txt index 9464659d..939424f8 100644 --- a/root/io/io/CMakeLists.txt +++ b/root/io/io/CMakeLists.txt @@ -37,5 +37,5 @@ if(rootbench-datafiles) TFile_ATLAS_Benchmarks.cxx LABEL short LIBRARIES Core RIO - DOWNLOAD_DATAFILES atlasopendata_mc_117050.ttbar_lep.root atlasopendata_DataMuons.root) + DOWNLOAD_DATAFILES atlasopendata_mc_117050.ttbar_lep.root) endif() \ No newline at end of file diff --git a/root/io/io/TFile_ATLAS_Benchmarks.cxx b/root/io/io/TFile_ATLAS_Benchmarks.cxx index e8b542c4..3393fcba 100644 --- a/root/io/io/TFile_ATLAS_Benchmarks.cxx +++ b/root/io/io/TFile_ATLAS_Benchmarks.cxx @@ -55,36 +55,9 @@ static void BM_ATLAS_Decompress(benchmark::State &state, int algo, std::string f gSystem->Exec(("rm -f " + new_filename).c_str()); } - -static void BM_ATLAS_Decompress_Real_ZLIB(benchmark::State &state) { - BM_ATLAS_Decompress(state, 1, "atlasopendata_DataMuons"); -} -static void BM_ATLAS_Decompress_Real_LZMA(benchmark::State &state) { - BM_ATLAS_Decompress(state, 2, "atlasopendata_DataMuons"); -} -static void BM_ATLAS_Decompress_Real_LZ4(benchmark::State &state) { - BM_ATLAS_Decompress(state, 4, "atlasopendata_DataMuons"); -} -static void BM_ATLAS_Decompress_Real_ZSTD(benchmark::State &state) { - BM_ATLAS_Decompress(state, 5, "atlasopendata_DataMuons"); -} - -BENCHMARK(BM_ATLAS_Decompress_Real_ZLIB) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(3); - -BENCHMARK(BM_ATLAS_Decompress_Real_LZMA) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(3); - -BENCHMARK(BM_ATLAS_Decompress_Real_LZ4) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(3); - -BENCHMARK(BM_ATLAS_Decompress_Real_ZSTD) -->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(3); - +// Benchmarks for ATLAS files of experimental (real) data are deleted +// because it takes very long time. +// TODO: find smaller file static void BM_ATLAS_Decompress_MC_ZLIB(benchmark::State &state) { BM_ATLAS_Decompress(state, 1, "atlasopendata_mc_117050.ttbar_lep"); @@ -101,19 +74,19 @@ static void BM_ATLAS_Decompress_MC_ZSTD(benchmark::State &state) { BENCHMARK(BM_ATLAS_Decompress_MC_ZLIB) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(3); +->Unit(benchmark::kMillisecond)->Iterations(2); BENCHMARK(BM_ATLAS_Decompress_MC_LZMA) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(3); +->Unit(benchmark::kMillisecond)->Iterations(2); BENCHMARK(BM_ATLAS_Decompress_MC_LZ4) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(3); +->Unit(benchmark::kMillisecond)->Iterations(2); BENCHMARK(BM_ATLAS_Decompress_MC_ZSTD) ->Arg(1)->Arg(6)->Arg(9) -->Unit(benchmark::kMillisecond)->Iterations(3); +->Unit(benchmark::kMillisecond)->Iterations(2); BENCHMARK_MAIN(); \ No newline at end of file From 0788fe51f25cd1e6bc3d9c900da1366fc37a755a Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 3 Sep 2026 17:21:08 +0000 Subject: [PATCH 5/6] Polish compression benchmarks Join the temporary file name to RB::GetTempFs() with a path separator as done everywhere else, since the returned path has no trailing slash. Remove the temporary file with gSystem->Unlink() instead of shelling out to rm, drop some pointless conversions through c_str(), and fix trailing whitespace and missing newlines at the end of files. --- root/io/io/CMakeLists.txt | 2 +- root/io/io/TFile_ATLAS_Benchmarks.cxx | 8 ++++---- root/io/io/TFile_LHCb_Benchmarks.cxx | 10 +++++----- root/io/io/TFile_NanoAOD_Benchmarks.cxx | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/root/io/io/CMakeLists.txt b/root/io/io/CMakeLists.txt index 939424f8..7d94b635 100644 --- a/root/io/io/CMakeLists.txt +++ b/root/io/io/CMakeLists.txt @@ -38,4 +38,4 @@ if(rootbench-datafiles) LABEL short LIBRARIES Core RIO DOWNLOAD_DATAFILES atlasopendata_mc_117050.ttbar_lep.root) -endif() \ No newline at end of file +endif() diff --git a/root/io/io/TFile_ATLAS_Benchmarks.cxx b/root/io/io/TFile_ATLAS_Benchmarks.cxx index 3393fcba..d19c2c22 100644 --- a/root/io/io/TFile_ATLAS_Benchmarks.cxx +++ b/root/io/io/TFile_ATLAS_Benchmarks.cxx @@ -25,8 +25,8 @@ static void BM_ATLAS_Decompress(benchmark::State &state, int algo, std::string f int comp_level = state.range(0); std::string comp_setting = std::to_string(algo * 100 + comp_level); - std::string old_filename = (RB::GetDataDir() + "/" + filename + ".root").c_str(); - std::string new_filename = (RB::GetTempFs() + "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root").c_str(); + std::string old_filename = (RB::GetDataDir() + "/" + filename + ".root"); + std::string new_filename = (RB::GetTempFs() + "/level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root"); gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); @@ -52,7 +52,7 @@ static void BM_ATLAS_Decompress(benchmark::State &state, int algo, std::string f } - gSystem->Exec(("rm -f " + new_filename).c_str()); + gSystem->Unlink(new_filename.c_str()); } // Benchmarks for ATLAS files of experimental (real) data are deleted @@ -89,4 +89,4 @@ BENCHMARK(BM_ATLAS_Decompress_MC_ZSTD) ->Unit(benchmark::kMillisecond)->Iterations(2); -BENCHMARK_MAIN(); \ No newline at end of file +BENCHMARK_MAIN(); diff --git a/root/io/io/TFile_LHCb_Benchmarks.cxx b/root/io/io/TFile_LHCb_Benchmarks.cxx index 7be6aca2..ca2ef5ed 100644 --- a/root/io/io/TFile_LHCb_Benchmarks.cxx +++ b/root/io/io/TFile_LHCb_Benchmarks.cxx @@ -25,8 +25,8 @@ static void BM_LHCb_Decompress(benchmark::State &state, int algo) { int comp_level = state.range(0); std::string comp_setting = std::to_string(algo * 100 + comp_level); - std::string old_filename = (RB::GetDataDir() + "/lhcb_B2ppKK2011_md_noPIDstrip.root").c_str(); - std::string new_filename = (RB::GetTempFs() + "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root"); + std::string old_filename = (RB::GetDataDir() + "/lhcb_B2ppKK2011_md_noPIDstrip.root"); + std::string new_filename = (RB::GetTempFs() + "/level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root"); gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); @@ -35,7 +35,7 @@ static void BM_LHCb_Decompress(benchmark::State &state, int algo) { newfile->Close(); for (auto _ : state) { - + TFile *hfile = new TFile(new_filename.c_str()); TTree *tree1 = (TTree*)hfile->Get("TupleB2ppKK/DecayTree"); TTree *tree2 = (TTree*)hfile->Get("TupleB2ppKPi/DecayTree"); @@ -64,7 +64,7 @@ static void BM_LHCb_Decompress(benchmark::State &state, int algo) { } - gSystem->Exec(("rm -f " + new_filename).c_str()); + gSystem->Unlink(new_filename.c_str()); } @@ -99,4 +99,4 @@ BENCHMARK(BM_LHCb_Decompress_ZSTD) ->Unit(benchmark::kMillisecond)->Iterations(3); -BENCHMARK_MAIN(); \ No newline at end of file +BENCHMARK_MAIN(); diff --git a/root/io/io/TFile_NanoAOD_Benchmarks.cxx b/root/io/io/TFile_NanoAOD_Benchmarks.cxx index 00557822..3a972b57 100644 --- a/root/io/io/TFile_NanoAOD_Benchmarks.cxx +++ b/root/io/io/TFile_NanoAOD_Benchmarks.cxx @@ -25,8 +25,8 @@ static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) { int comp_level = state.range(0); std::string comp_setting = std::to_string(algo * 100 + comp_level); - std::string old_filename = (RB::GetDataDir() + "/Run2012B_DoubleElectron.root").c_str(); - std::string new_filename = (RB::GetTempFs() + "level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root").c_str(); + std::string old_filename = (RB::GetDataDir() + "/Run2012B_DoubleElectron.root"); + std::string new_filename = (RB::GetTempFs() + "/level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root"); gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); @@ -35,7 +35,7 @@ static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) { newfile->Close(); for (auto _ : state) { - + TFile *hfile = new TFile(new_filename.c_str()); TTree *tree = (TTree*)hfile->Get("Events"); @@ -52,7 +52,7 @@ static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) { } - gSystem->Exec(("rm -f " + new_filename).c_str()); + gSystem->Unlink(new_filename.c_str()); } From 04bd6ec6464565a47ecfd6f64a97c743c266cc7f Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 3 Sep 2026 17:26:05 +0000 Subject: [PATCH 6/6] Skip compression benchmarks gracefully if hadd fails If hadd fails (e.g. because the input file is missing), the benchmarks would crash with a segmentation fault when reading the tree from the file that was never created. Report the error via the benchmark state instead. --- root/io/io/TFile_ATLAS_Benchmarks.cxx | 5 ++++- root/io/io/TFile_LHCb_Benchmarks.cxx | 5 ++++- root/io/io/TFile_NanoAOD_Benchmarks.cxx | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/root/io/io/TFile_ATLAS_Benchmarks.cxx b/root/io/io/TFile_ATLAS_Benchmarks.cxx index d19c2c22..8014c53a 100644 --- a/root/io/io/TFile_ATLAS_Benchmarks.cxx +++ b/root/io/io/TFile_ATLAS_Benchmarks.cxx @@ -28,7 +28,10 @@ static void BM_ATLAS_Decompress(benchmark::State &state, int algo, std::string f std::string old_filename = (RB::GetDataDir() + "/" + filename + ".root"); std::string new_filename = (RB::GetTempFs() + "/level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root"); - gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); + if (gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()) != 0) { + state.SkipWithError(("hadd failed to recompress " + old_filename).c_str()); + return; + } TFile *newfile = new TFile(new_filename.c_str()); state.counters["comp_size"] = newfile->GetSize(); diff --git a/root/io/io/TFile_LHCb_Benchmarks.cxx b/root/io/io/TFile_LHCb_Benchmarks.cxx index ca2ef5ed..cecd4439 100644 --- a/root/io/io/TFile_LHCb_Benchmarks.cxx +++ b/root/io/io/TFile_LHCb_Benchmarks.cxx @@ -28,7 +28,10 @@ static void BM_LHCb_Decompress(benchmark::State &state, int algo) { std::string old_filename = (RB::GetDataDir() + "/lhcb_B2ppKK2011_md_noPIDstrip.root"); std::string new_filename = (RB::GetTempFs() + "/level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root"); - gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); + if (gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()) != 0) { + state.SkipWithError(("hadd failed to recompress " + old_filename).c_str()); + return; + } TFile *newfile = new TFile(new_filename.c_str()); state.counters["comp_size"] = newfile->GetSize(); diff --git a/root/io/io/TFile_NanoAOD_Benchmarks.cxx b/root/io/io/TFile_NanoAOD_Benchmarks.cxx index 3a972b57..310b221f 100644 --- a/root/io/io/TFile_NanoAOD_Benchmarks.cxx +++ b/root/io/io/TFile_NanoAOD_Benchmarks.cxx @@ -28,7 +28,10 @@ static void BM_NanoAOD_Decompress(benchmark::State &state, int algo) { std::string old_filename = (RB::GetDataDir() + "/Run2012B_DoubleElectron.root"); std::string new_filename = (RB::GetTempFs() + "/level_" + std::to_string(comp_level) + "_nanoaod_" + GetAlgoName(algo) + ".root"); - gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()); + if (gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str()) != 0) { + state.SkipWithError(("hadd failed to recompress " + old_filename).c_str()); + return; + } TFile *newfile = new TFile(new_filename.c_str()); state.counters["comp_size"] = newfile->GetSize();