{
"cells": [
{
"cell_type": "markdown",
"id": "bfe655f9",
"metadata": {},
"source": [
"# bill\n",
"Benchmark comparing row-wise and column-wise storage performance\n",
"\n",
"The test consists in writing/reading to/from keys or trees\n",
"To execute the benchmark:\n",
"```\n",
"root -b -q bill.C or root -b -q bill.C++\n",
"```\n",
"for example for N=10000, the following output is produced\n",
"on an 2.7 GHz Intel Core i7 (year 2011).\n",
"The names featuring a \"t\" are relative to trees, the faster, the better.\n",
"```\n",
"billw0 : RT= 0.803 s, Cpu= 0.800 s, File size= 45608143 bytes, CX= 1\n",
"billr0 : RT= 0.388 s, Cpu= 0.390 s\n",
"billtw0 : RT= 0.336 s, Cpu= 0.310 s, File size= 45266881 bytes, CX= 1.00034\n",
"billtr0 : RT= 0.229 s, Cpu= 0.230 s\n",
"billw1 : RT= 1.671 s, Cpu= 1.670 s, File size= 16760526 bytes, CX= 2.72078\n",
"billr1 : RT= 0.667 s, Cpu= 0.680 s\n",
"billtw1 : RT= 0.775 s, Cpu= 0.770 s, File size= 9540884 bytes, CX= 4.74501\n",
"billtr1 : RT= 0.352 s, Cpu= 0.350 s\n",
"billtot : RT= 5.384 s, Cpu= 5.290 s\n",
"******************************************************************\n",
"* ROOTMARKS =1763.9 * Root6.05/03 20150914/948\n",
"******************************************************************\n",
"```\n",
"\n",
"\n",
"**Author:** Rene Brun \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, March 19, 2024 at 07:21 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1d3db2ba",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:21:19.385758Z",
"iopub.status.busy": "2024-03-19T19:21:19.385399Z",
"iopub.status.idle": "2024-03-19T19:21:19.519671Z",
"shell.execute_reply": "2024-03-19T19:21:19.490214Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"#include \"TFile.h\"\n",
"#include \"TSystem.h\"\n",
"#include \"TH1.h\"\n",
"#include \"TRandom.h\"\n",
"#include \"TStopwatch.h\"\n",
"#include \"TKey.h\"\n",
"#include \"TTree.h\"\n",
"#include \"TROOT.h\"\n",
"\n",
"const Int_t N = 10000; //number of events to be processed\n",
"TStopwatch timer;"
]
},
{
"cell_type": "markdown",
"id": "c89eab86",
"metadata": {},
"source": [
" Definition of a helper function: "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "91b51d02",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:21:19.548980Z",
"iopub.status.busy": "2024-03-19T19:21:19.548605Z",
"iopub.status.idle": "2024-03-19T19:21:19.611567Z",
"shell.execute_reply": "2024-03-19T19:21:19.610144Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"void billw(const char *billname, Int_t compress) {\n",
" //write N histograms as keys\n",
" timer.Start();\n",
" TFile f(billname,\"recreate\",\"bill benchmark with keys\",compress);\n",
" TH1F h(\"h\",\"h\",1000,-3,3);\n",
" h.FillRandom(\"gaus\",50000);\n",
"\n",
" for (Int_t i=0;iRndm());\n",
" h.Write();\n",
" }\n",
" timer.Stop();\n",
" printf(\"billw%d : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\\n\",compress,timer.RealTime(),timer.CpuTime(),\n",
" (Int_t)f.GetBytesWritten(),f.GetCompressionFactor());\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "946b09a5",
"metadata": {},
"source": [
" Definition of a helper function: "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dc0051de",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:21:19.628138Z",
"iopub.status.busy": "2024-03-19T19:21:19.627746Z",
"iopub.status.idle": "2024-03-19T19:21:19.738210Z",
"shell.execute_reply": "2024-03-19T19:21:19.736937Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"void billr(const char *billname, Int_t compress) {\n",
" //read N histograms from keys\n",
" timer.Start();\n",
" TFile f(billname);\n",
" TIter next(f.GetListOfKeys());\n",
" TH1F *h;\n",
" TH1::AddDirectory(kFALSE);\n",
" TKey *key;\n",
" Int_t i=0;\n",
" TH1F *hmean = new TH1F(\"hmean\",\"hist mean from keys\",100,0,1);\n",
"\n",
" while ((key=(TKey*)next())) {\n",
" h = (TH1F*)key->ReadObj();\n",
" hmean->Fill(h->GetMean());\n",
" delete h;\n",
" i++;\n",
" }\n",
" timer.Stop();\n",
" printf(\"billr%d : RT=%7.3f s, Cpu=%7.3f s\\n\",compress,timer.RealTime(),timer.CpuTime());\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "67be382a",
"metadata": {},
"source": [
" Definition of a helper function: "
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5ad8d502",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:21:19.754715Z",
"iopub.status.busy": "2024-03-19T19:21:19.754337Z",
"iopub.status.idle": "2024-03-19T19:21:19.918937Z",
"shell.execute_reply": "2024-03-19T19:21:19.901748Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"void billtw(const char *billtname, Int_t compress) {\n",
" //write N histograms to a Tree\n",
" timer.Start();\n",
" TFile f(billtname,\"recreate\",\"bill benchmark with trees\",compress);\n",
" TH1F *h = new TH1F(\"h\",\"h\",1000,-3,3);\n",
" h->FillRandom(\"gaus\",50000);\n",
" TTree *T = new TTree(\"T\",\"test bill\");\n",
" T->Branch(\"event\",\"TH1F\",&h,64000,0);\n",
" for (Int_t i=0;iSetName(name);\n",
" h->Fill(2*gRandom->Rndm());\n",
" T->Fill();\n",
" }\n",
" T->Write();\n",
" delete T;\n",
" timer.Stop();\n",
" printf(\"billtw%d : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\\n\",compress,timer.RealTime(),timer.CpuTime(),\n",
" (Int_t)f.GetBytesWritten(),f.GetCompressionFactor());\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "0b43eeb3",
"metadata": {},
"source": [
" Definition of a helper function: "
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "4f6ea297",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:21:20.000906Z",
"iopub.status.busy": "2024-03-19T19:21:20.000523Z",
"iopub.status.idle": "2024-03-19T19:21:20.046380Z",
"shell.execute_reply": "2024-03-19T19:21:20.037019Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"void billtr(const char *billtname, Int_t compress) {\n",
" //read N histograms from a tree\n",
" timer.Start();\n",
" TFile f(billtname);\n",
" TH1F *h = nullptr;\n",
" TTree *T = (TTree*)f.Get(\"T\");\n",
" T->SetBranchAddress(\"event\",&h);\n",
" TH1F *hmeant = new TH1F(\"hmeant\",\"hist mean from tree\",100,0,1);\n",
" Long64_t nentries = T->GetEntries();\n",
" for (Long64_t i=0;iGetEntry(i);\n",
" hmeant->Fill(h->GetMean());\n",
" }\n",
" timer.Stop();\n",
" printf(\"billtr%d : RT=%7.3f s, Cpu=%7.3f s\\n\",compress,timer.RealTime(),timer.CpuTime());\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0195e6b5",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:21:20.068750Z",
"iopub.status.busy": "2024-03-19T19:21:20.068365Z",
"iopub.status.idle": "2024-03-19T19:21:27.388589Z",
"shell.execute_reply": "2024-03-19T19:21:27.372361Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"billw0 : RT= 0.734 s, Cpu= 0.640 s, File size= 45768009 bytes, CX= 1\n",
"billr0 : RT= 0.397 s, Cpu= 0.360 s\n",
"billtw0 : RT= 0.429 s, Cpu= 0.320 s, File size= 45442799 bytes, CX= 1\n",
"billtr0 : RT= 0.172 s, Cpu= 0.160 s\n",
"billw1 : RT= 1.925 s, Cpu= 1.850 s, File size= 16835471 bytes, CX= 2.71817\n",
"billr1 : RT= 0.618 s, Cpu= 0.620 s\n",
"billtw1 : RT= 0.771 s, Cpu= 0.700 s, File size= 9557221 bytes, CX= 4.75363\n",
"billtr1 : RT= 0.292 s, Cpu= 0.280 s\n",
"billtot : RT= 5.839 s, Cpu= 5.050 s\n"
]
}
],
"source": [
"TString dir = gSystem->GetDirName(gSystem->UnixPathName(__FILE__));\n",
"TString bill = dir + \"/bill.root\";\n",
"TString billt = dir + \"/billt.root\";\n",
"\n",
"TStopwatch totaltimer;\n",
"totaltimer.Start();\n",
"for (Int_t compress=0;compress<2;compress++) {\n",
" billw(bill,compress);\n",
" billr(bill,compress);\n",
" billtw(billt,compress);\n",
" billtr(billt,compress);\n",
"}\n",
"gSystem->Unlink(bill);\n",
"gSystem->Unlink(billt);\n",
"totaltimer.Stop();\n",
"Double_t realtime = totaltimer.RealTime();\n",
"Double_t cputime = totaltimer.CpuTime();\n",
"printf(\"billtot : RT=%7.3f s, Cpu=%7.3f s\\n\",realtime,cputime);"
]
},
{
"cell_type": "markdown",
"id": "9ab28eb5",
"metadata": {},
"source": [
"reference is a P IV 2.4 GHz"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "775a8b9e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:21:27.428520Z",
"iopub.status.busy": "2024-03-19T19:21:27.428122Z",
"iopub.status.idle": "2024-03-19T19:21:27.661648Z",
"shell.execute_reply": "2024-03-19T19:21:27.660689Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"******************************************************************\n",
"* ROOTMARKS =1729.1 * Root6.31/01 20231010/0\n",
"******************************************************************\n"
]
}
],
"source": [
"Float_t rootmarks = 600*(16.98 + 14.40)/(realtime + cputime);\n",
"printf(\"******************************************************************\\n\");\n",
"printf(\"* ROOTMARKS =%6.1f * Root%-8s %d/%d\\n\",rootmarks,gROOT->GetVersion(),gROOT->GetVersionDate(),gROOT->GetVersionTime());\n",
"printf(\"******************************************************************\\n\");"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}