#include #include #include #include #include #include #include "TH1F.h" #include "TH2F.h" /* g++ TestSpeed.cpp -O2 -g -ggdb $(root-config --cflags) $(root-config --libs) -lfmt -o compare -I /home/sbhawani/alice/sw/ubuntu2004_x86-64/boost/latest/include/ -I /home/sbhawani/alice/sw/ubuntu2004_x86-64/fmt/latest/include/ -L /home/sbhawani/alice/sw/ubuntu2004_x86-64/fmt/latest/lib/ */ void compare_boost_rootOriginal() { using timer = std::chrono::high_resolution_clock; namespace bh = boost::histogram; // ===| binning |============================================================= const int nBins = 100; const float xMin = 0.; const float xMax = 1.; const size_t inputValues = 1000000; // ===| histograms |========================================================== auto h1Boost = bh::make_histogram(bh::axis::regular<>(nBins, xMin, xMax, "random")); TH1F h1Root = TH1F("h", ";random", nBins, xMin, xMax); // here you can create another BoostHistogram //auto h2Boost = bh::make_histogram(bh::axis::regular<>(nBins, xMin, xMax, "random")); // ===| input values |======================================================== std::random_device rd; // Will be used to obtain a seed for the random number engine std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd() std::uniform_real_distribution<> dis(.0, 1.0); std::vector randomValues(inputValues); for (auto &val : randomValues) { val = dis(gen); } // ===| fill root |=========================================================== auto startRoot = timer::now(); for (const auto &val : randomValues) { h1Root.Fill(val); } auto stopRoot = timer::now(); std::chrono::duration timeRoot = stopRoot - startRoot; // ===| fill boost |========================================================== auto startBoost = timer::now(); for (const auto &val : randomValues) { h1Boost(val); } auto stopBoost = timer::now(); std::chrono::duration timeBoost = stopBoost - startBoost; // ===| output |============================================================== fmt::print("time for boost: {}, time for root: {}, ratio: {}\n", timeBoost, timeRoot, timeBoost / timeRoot); } int main() { compare_boost_rootOriginal(); }