1919 * Benchmark a simple mock fit model
2020 * sum(x) = frac * Gauss(x) + (1-frac) * Exponential(x)
2121 *
22- * Run 6 different workflows:
23- * 0. Evaluate fit model for 2 M data events with batch data loading and SIMD (if compiler flags activated).
22+ * We can run 6 different workflows:
23+ * 0. Evaluate fit model for 1 M data events with batch data loading and SIMD (if compiler flags activated).
2424 * 1. As above, but use old RooFit strategy of single-value data loading.
2525 * 2. Compute probabilities for each data event. That is, run step 0 and normalise values.
2626 * 3. As above, but use old RooFit strategy.
3838#include " RooExponential.h"
3939#include " RooDataSet.h"
4040#include " RunContext.h"
41-
4241#include " RooRandom.h"
42+
43+ #include " SlowRooExponential.h"
44+
4345void randomiseParameters (const RooArgSet& parameters, ULong_t seed=0 ) {
4446 auto random = RooRandom::randomGenerator ();
4547 if (seed != 0 )
@@ -61,9 +63,10 @@ enum RunConfig_t {runBatchUnnorm = 0, runSingleUnnorm = 1,
6163
6264
6365static void benchAddPdfGaussExp (benchmark::State& state) {
64- RunConfig_t runConfig = static_cast <RunConfig_t>(state.range (0 ));
65- constexpr std::size_t nParamSets = 30 ;
66- constexpr std::size_t nEvents = 2000000 ;
66+ const RunConfig_t runConfig = static_cast <RunConfig_t>(state.range (0 ));
67+ const bool useSlowRooExponential = state.range (1 );
68+ constexpr std::size_t nParamSets = 3 ;
69+ constexpr std::size_t nEvents = 1000000 ;
6770
6871 // Declare variables x,mean,sigma with associated name, title, initial value and allowed range
6972 RooRealVar x (" x" , " x" , -1.5 , 40.5 );
@@ -75,10 +78,15 @@ static void benchAddPdfGaussExp(benchmark::State& state) {
7578 RooGaussian gauss (" gauss" , " gaussian PDF" , x, mean, sigma);
7679
7780 RooRealVar c1 (" c1" , " Decay constant" , -0.5 , -10 , -0.001 );
78- RooExponential ex (" Pois" , " Poisson PDF" , x, c1);
81+ std::unique_ptr<RooAbsPdf> ex;
82+ if (useSlowRooExponential) {
83+ ex = std::make_unique<SlowRooExponential>(" Pois" , " Poisson PDF" , x, c1);
84+ } else {
85+ ex = std::make_unique<RooExponential>(" Pois" , " Poisson PDF" , x, c1);
86+ }
7987
8088 RooRealVar fractionGaus (" fractionGaus" , " Fraction of Gauss component" , 0.5 , 0 ., 1 .);
81- RooAddPdf pdf (" SumGausPois" , " Sum of Gaus and Poisson" , RooArgSet (gauss, ex), fractionGaus);
89+ RooAddPdf pdf (" SumGausPois" , " Sum of Gaus and Poisson" , RooArgSet (gauss, * ex), fractionGaus);
8290 // to avoid a warning when computing the unnormalized RooAddPdf values
8391 pdf.fixCoefNormalization (x);
8492
@@ -92,15 +100,19 @@ static void benchAddPdfGaussExp(benchmark::State& state) {
92100 RooBatchCompute::RunContext evalData;
93101 std::vector<double > results (nEvents);
94102
103+ std::array<RooArgSet, nParamSets> paramSets;
104+ unsigned int seed = 1337 ;
105+ for (auto & paramSet : paramSets) {
106+ randomiseParameters (parameters, seed++);
107+ parameters.snapshot (paramSet);
108+ }
109+
95110 for (auto _ : state) {
96- for (unsigned int paramSetIndex=0 ; paramSetIndex < nParamSets; ++paramSetIndex) {
97- state.PauseTiming ();
98- randomiseParameters (parameters, 1337 +paramSetIndex);
99- state.ResumeTiming ();
111+ for (const auto & paramSet : paramSets) {
112+ parameters = paramSet;
100113
101114 evalData.clear ();
102115 data->getBatches (evalData, 0 , data->numEntries ());
103- runConfig = static_cast <RunConfig_t>(runConfig % 6 );
104116
105117 if (runConfig == runBatchUnnorm) {
106118 auto batchResult = pdf.getValues (evalData, nullptr );
@@ -134,14 +146,17 @@ static void benchAddPdfGaussExp(benchmark::State& state) {
134146 }
135147};
136148
137- BENCHMARK (benchAddPdfGaussExp)->Unit(benchmark::kMillisecond )
138- ->Args({runBatchUnnorm})
139- ->Args({runSingleUnnorm})
140- ->Args({runBatchNorm})
141- ->Args({runSingleNorm})
142- ->Args({runBatchNormLogs})
143- ->Args({runSingleNormLogs})
144- ;
149+ BENCHMARK (benchAddPdfGaussExp)->Name(" Gauss+Exp" )->Unit(benchmark::kMillisecond )
150+ ->Args({runBatchNorm, false })
151+ ->Args({runSingleNorm, false })
152+ ->Args({runBatchNormLogs, false })
153+ ->Args({runSingleNormLogs, false });
154+ BENCHMARK (benchAddPdfGaussExp)->Name(" Gauss+Exp(evaluateSpan fallback)" )->Unit(benchmark::kMillisecond )
155+ ->Args({runBatchNorm, true })
156+ ->Args({runSingleNorm, true })
157+ ->Args({runBatchNormLogs, true })
158+ ->Args({runSingleNormLogs, true });
159+
145160
146161
147162BENCHMARK_MAIN ();
0 commit comments