Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compression benchmarks #179

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions root/io/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ if(rootbench-datafiles)
LIBRARIES Core RIO
DOWNLOAD_DATAFILES Event0-sample.root)

# 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)
endif()
109 changes: 36 additions & 73 deletions root/io/io/TFile_ATLAS_Benchmarks.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "TFile.h"
#include "TTree.h"
#include "TSystem.h"

#include "benchmark/benchmark.h"
#include "rootbench/RBConfig.h"
Expand All @@ -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, std::string filename) {

int comp_level = state.range(0);
std::string filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root";
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();

for (auto _ : state) {
state.PauseTiming();

TFile *newfile = new TFile(filename.c_str(), "recreate");
TTree *newtree = oldtree->CloneTree();
newfile->SetCompressionAlgorithm(algo);
newfile->SetCompressionLevel(comp_level);
gSystem->Exec(("hadd -v 0 -f" + comp_setting + " " + new_filename + " " + old_filename).c_str());

state.ResumeTiming();
newfile->Write();
state.PauseTiming();
TFile *newfile = new TFile(new_filename.c_str());
state.counters["comp_size"] = newfile->GetSize();
newfile->Close();

state.counters["comp_size"] = newfile->GetBytesWritten();
newfile->Close();

state.ResumeTiming();
}
}

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) {
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();
Expand All @@ -62,68 +47,46 @@ 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);
// 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");
}
static void BM_ATLAS_Decompress_LZMA(benchmark::State &state) {
BM_ATLAS_Decompress(state, 2);
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_LZ4(benchmark::State &state) {
BM_ATLAS_Decompress(state, 4);
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_ZSTD(benchmark::State &state) {
BM_ATLAS_Decompress(state, 5);
static void BM_ATLAS_Decompress_MC_ZSTD(benchmark::State &state) {
BM_ATLAS_Decompress(state, 5, "atlasopendata_mc_117050.ttbar_lep");
}


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)
BENCHMARK(BM_ATLAS_Decompress_MC_ZLIB)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(2);

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(2);

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(2);

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(2);


BENCHMARK_MAIN();
BENCHMARK_MAIN();
85 changes: 21 additions & 64 deletions root/io/io/TFile_LHCb_Benchmarks.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "TFile.h"
#include "TTree.h"
#include "TSystem.h"

#include "benchmark/benchmark.h"
#include "rootbench/RBConfig.h"
Expand All @@ -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 = (RB::GetTempFs() + "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();

state.ResumeTiming();
}
}
TFile *newfile = new TFile(new_filename.c_str());
state.counters["comp_size"] = newfile->GetSize();
newfile->Close();

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");
Expand All @@ -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);
}
Expand All @@ -108,38 +82,21 @@ 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);
->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();
BENCHMARK_MAIN();
Loading