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

Improved benchmarking of compression algorithms #225

Open
wants to merge 1 commit 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
9 changes: 8 additions & 1 deletion cmake/modules/RootBenchOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
# # TBD: to introduce special function for options (similar to root.git)
#----------------------------------------------------------------------------
option(coverage OFF)
option(rootbench-datafiles OFF)

option(rootbench-datafiles OFF "Download files from root.cern.ch")

option(experiment-datafiles OFF "Use for benchmarking CMS and ATLAS files (> 1.5 GB)")
if(experiment-datafiles)
# We need to enable download of datafiles from oot.cern.ch
set(rootbench-datafiles ON CACHE BOOL "Download files from root.cern.ch" FORCE)
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a separate option? other files downloaded if rootbench-datafiles is on are not much smaller, and now we have two options that we need to set to get all benchmarks.

if we need the option, why does it imply root-benchdatafiles=ON? it would be simpler to keep them orthogonal - one turns on some benchmarks, the other turns on some other.

if we need the second option, it needs at least to be mentioned in the README.

36 changes: 18 additions & 18 deletions root/io/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ if(ROOT_root7_FOUND) # using ROOT_root7_FOUND as a proxy for "c++ standard >= 14
RB_ADD_GBENCHMARK(TFile_RDFSnapshot
TFile_RDFSnapshot.cxx
LABEL short
LIBRARIES Core RIO ROOTDataFrame Tree TreePlayer MathCore)
LIBRARIES Core RIO ROOTDataFrame Tree TreePlayer MathCore)
endif()

if(rootbench-datafiles)
if(rootbench-datafiles AND experiment-datafiles)

# FIXME:Compression tests needs to have libEvent.so which is a part of ROOT build
# Preloading doesn't help...
#if(TARGET Event)
Expand All @@ -21,22 +22,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 Tree
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 Tree
DOWNLOAD_DATAFILES Run2012B_DoubleMuParked.root NanoAOD_DoubleMuon_CMS2011OpenData.root)

#RB_ADD_GBENCHMARK(CompressionBenchmarks_ATLAS
# TFile_ATLAS_Benchmarks.cxx
# LABEL short
# LIBRARIES Core RIO
# DOWNLOAD_DATAFILES gg_data-zstd.root)
RB_ADD_GBENCHMARK(CompressionBenchmarks_ATLAS
TFile_ATLAS_Benchmarks.cxx
LABEL short
LIBRARIES Core RIO Tree
DOWNLOAD_DATAFILES gg_data-zstd.root)
endif()
63 changes: 37 additions & 26 deletions root/io/io/TFile_ATLAS_Benchmarks.cxx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "TFile.h"
#include "TTree.h"
#include "TStopwatch.h"

#include "benchmark/benchmark.h"
#include "rootbench/RBConfig.h"

#include <map>
#include <iostream>

static std::string GetAlgoName(int algo) {
std::map<int, std::string> algoName = {
Expand All @@ -21,47 +23,57 @@ static std::string GetAlgoName(int algo) {
}

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");

std::string path = RB::GetDataDir() + "/gg_data-zstd.root";
auto oldfile = TFile::Open(path.c_str());
auto oldtree = oldfile->Get<TTree>("mini");
TStopwatch timer;
const auto nevents = oldtree->GetEntries();
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();
auto newfile = new TFile(filename.c_str(), "recreate");
newfile->SetCompressionAlgorithm(algo);
newfile->SetCompressionLevel(comp_level);
auto newtree = oldtree->CloneTree();

state.ResumeTiming();
timer.Start();
newfile->Write();
timer.Stop();
state.PauseTiming();

state.counters["comp_size"] = newfile->GetBytesWritten();
state.counters["comp_size"] = newfile->GetSize();
double rtime = timer.RealTime();
double ctime = timer.CpuTime();
state.counters["mb_rts"] = newfile->GetSize()/rtime;
state.counters["mb_cts"] = newfile->GetSize()/ctime;
newfile->Close();

state.ResumeTiming();
}
}

static void BM_ATLAS_Decompress(benchmark::State &state, int algo) {
int comp_level = state.range(0);

int nb;
TStopwatch timer;
std::string filename = "level_" + std::to_string(comp_level) + "_atlas_" + GetAlgoName(algo) + ".root";
for (auto _ : state) {
TFile *hfile = new TFile(filename.c_str());
TTree *tree = (TTree*)hfile->Get("mini");

Int_t nevent = (Int_t)tree->GetEntries();

Int_t nb = 0;
timer.Start();
TFile f(filename.c_str());
auto tree = static_cast<TTree *>(f.Get("mini"));
const auto nevents = tree->GetEntries();
Int_t ev;

for (ev = 0; ev < nevent; ev++) {
for (ev = 0; ev < nevents; ++ev) {
nb += tree->GetEntry(ev);
}
timer.Stop();
double rtime = timer.RealTime();
double ctime = timer.CpuTime();
state.counters["mb_rts"] = f.GetSize()/rtime;
state.counters["mb_cts"] = f.GetSize()/ctime;
f.Close();
}
}

Expand Down Expand Up @@ -91,39 +103,38 @@ static void BM_ATLAS_Decompress_ZSTD(benchmark::State &state) {
BM_ATLAS_Decompress(state, 5);
}


BENCHMARK(BM_ATLAS_Compress_ZLIB)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_ATLAS_Compress_LZMA)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_ATLAS_Compress_LZ4)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_ATLAS_Compress_ZSTD)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);


BENCHMARK(BM_ATLAS_Decompress_ZLIB)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_ATLAS_Decompress_LZMA)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_ATLAS_Decompress_LZ4)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_ATLAS_Decompress_ZSTD)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);


BENCHMARK_MAIN();
3 changes: 1 addition & 2 deletions root/io/io/TFile_CompressionBenchmarks_MainEvent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ static void BM_MainEvent_Decompress_ZSTD(benchmark::State &state) {
BM_MainEvent_Decompress(state, 5);
}



BENCHMARK(BM_MainEvent_Compress_ZLIB)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
Expand Down Expand Up @@ -138,4 +136,5 @@ BENCHMARK(BM_MainEvent_Decompress_ZSTD)
->Unit(benchmark::kMillisecond)->Iterations(5);



BENCHMARK_MAIN();
69 changes: 39 additions & 30 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 "TStopwatch.h"

#include "benchmark/benchmark.h"
#include "rootbench/RBConfig.h"
Expand All @@ -21,6 +22,7 @@ static std::string GetAlgoName(int algo) {
}

static void BM_LHCb_Compress(benchmark::State &state, int algo) {
TStopwatch timer;
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");
Expand All @@ -31,19 +33,24 @@ static void BM_LHCb_Compress(benchmark::State &state, int algo) {

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();
auto newfile = new TFile(filename.c_str(), "recreate");
newfile->SetCompressionAlgorithm(algo);
newfile->SetCompressionLevel(comp_level);
auto newtree1 = oldtree1->CloneTree();
auto newtree2 = oldtree2->CloneTree();
auto newtree3 = oldtree3->CloneTree();

state.ResumeTiming();
timer.Start();
newfile->Write();
timer.Stop();
state.PauseTiming();

state.counters["comp_size"] = newfile->GetBytesWritten();
state.counters["comp_size"] = newfile->GetSize();
double rtime = timer.RealTime();
double ctime = timer.CpuTime();
state.counters["mb_rts"] = newfile->GetSize()/rtime;
state.counters["mb_cts"] = newfile->GetSize()/ctime;
newfile->Close();

state.ResumeTiming();
Expand All @@ -52,32 +59,35 @@ static void BM_LHCb_Compress(benchmark::State &state, int algo) {

static void BM_LHCb_Decompress(benchmark::State &state, int algo) {
int comp_level = state.range(0);

TStopwatch timer;
std::string filename = "level_" + std::to_string(comp_level) + "_lhcb_" + GetAlgoName(algo) + ".root";
for (auto _ : state) {
TFile *hfile = new TFile(filename.c_str());
TTree *tree1 = (TTree*)hfile->Get("TupleB2ppKK/DecayTree");
TTree *tree2 = (TTree*)hfile->Get("TupleB2ppKPi/DecayTree");
TTree *tree3 = (TTree*)hfile->Get("TupleB2ppPiPi/DecayTree");

Int_t nevent1 = (Int_t)tree1->GetEntries();
Int_t nevent2 = (Int_t)tree2->GetEntries();
Int_t nevent3 = (Int_t)tree3->GetEntries();
timer.Start();
TFile f(filename.c_str());
auto tree1 = static_cast<TTree *>(f.Get("TupleB2ppKK/DecayTree"));
auto tree2 = static_cast<TTree *>(f.Get("TupleB2ppKPi/DecayTree"));
auto tree3 = static_cast<TTree *>(f.Get("TupleB2ppPiPi/DecayTree"));
const auto nevent1 = tree1->GetEntries();
const auto nevent2 = tree2->GetEntries();
const auto nevent3 = tree3->GetEntries();

Int_t nb = 0;
Int_t ev;

for (ev = 0; ev < nevent1; ev++) {
for (ev = 0; ev < nevent1; ++ev) {
nb += tree1->GetEntry(ev);
}

for (ev = 0; ev < nevent2; ev++) {
for (ev = 0; ev < nevent2; ++ev) {
nb += tree2->GetEntry(ev);
}

for (ev = 0; ev < nevent3; ev++) {
for (ev = 0; ev < nevent3; ++ev) {
nb += tree3->GetEntry(ev);
}
timer.Stop();
double rtime = timer.RealTime();
double ctime = timer.CpuTime();
state.counters["mb_rts"] = f.GetSize()/rtime;
state.counters["mb_cts"] = f.GetSize()/ctime;
f.Close();
}
}

Expand Down Expand Up @@ -110,36 +120,35 @@ 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);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_LHCb_Compress_LZMA)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_LHCb_Compress_LZ4)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_LHCb_Compress_ZSTD)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);

->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_LHCb_Decompress_ZLIB)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_LHCb_Decompress_LZMA)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_LHCb_Decompress_LZ4)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);

BENCHMARK(BM_LHCb_Decompress_ZSTD)
->Arg(1)->Arg(6)->Arg(9)
->Unit(benchmark::kMillisecond)->Iterations(5);
->Unit(benchmark::kMillisecond)->Iterations(1);


BENCHMARK_MAIN();
Loading