Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
perf.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_v7
3///
4/// \macro_code
5///
6/// \date 2015-07-08
7/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
8/// is welcome!
9/// \author Axel Naumann <axel@cern.ch>
10
11/*************************************************************************
12 * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
13 * All rights reserved. *
14 * *
15 * For the licensing terms see $ROOTSYS/LICENSE. *
16 * For the list of contributors see $ROOTSYS/README/CREDITS. *
17 *************************************************************************/
18
19#include "ROOT/RHist.hxx"
20#include "ROOT/RFit.hxx"
22
23#include <chrono>
24#include <iostream>
25#include <type_traits>
26
27using namespace ROOT;
28
29long createNew(int count)
30{
31 long ret = 1;
32 for (int i = 0; i < count; ++i) {
33 Experimental::RH2D hist({{{100, 0., 1.}, {{0., 1., 2., 3., 10.}}}});
34 ret ^= (long)&hist;
35 }
36 return ret;
37}
38
39long fillNew(int count)
40{
41 Experimental::RH2D hist({{{100, 0., 1.}, {{0., 1., 2., 3., 10.}}}});
42 for (int i = 0; i < count; ++i)
43 hist.Fill({0.611, 0.611});
44 return hist.GetNDim();
45}
46
47long fillN(int count)
48{
49 Experimental::RH2D hist({{{100, 0., 1.}, {{0., 1., 2., 3., 10.}}}});
50 std::vector<Experimental::Hist::RCoordArray<2>> v(count);
51 for (int i = 0; i < count; ++i)
52 v[i] = {0.611, 0.611};
53 hist.FillN(v);
54 return hist.GetNDim();
55}
56
57long fillBufferedNew(int count)
58{
59 Experimental::RH2D hist({{{100, 0., 1.}, {{0., 1., 2., 3., 10.}}}});
61 for (int i = 0; i < count; ++i)
62 filler.Fill({0.611, 0.611});
63 return hist.GetNDim();
64}
65
66using timefunc_t = std::add_pointer_t<long(int)>;
67
68void time1(timefunc_t run, int count, const std::string &name)
69{
70 using namespace std::chrono;
71 auto start = high_resolution_clock::now();
72 run(count);
73 auto end = high_resolution_clock::now();
74 duration<double> time_span = duration_cast<duration<double>>(end - start);
75
76 std::cout << count << " * " << name << ": " << time_span.count() << "seconds \n";
77}
78
79void time(timefunc_t r7, int count, const std::string &name)
80{
81 time1(r7, count, name + " (ROOT7)");
82}
83
84void perf()
85{
86 time(createNew, 1000000, "create 2D hists");
87 time(fillNew, 100000000, "2D fills");
88 time(fillBufferedNew, 100000000, "2D fills (buffered)");
89}
char name[80]
Definition TGX11.cxx:110
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
Definition RHist.hxx:53
void Fill(const CoordArray_t &x, Weight_t weight=(Weight_t) 1) noexcept
Add weight to the bin containing coordinate x.
Definition RHist.hxx:140
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.