Logo ROOT   6.07/09
Reference Guide
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 is welcome!
8 /// \author Axel Naumann <axel@cern.ch>
9 
10 /*************************************************************************
11  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
12  * All rights reserved. *
13  * *
14  * For the licensing terms see $ROOTSYS/LICENSE. *
15  * For the list of contributors see $ROOTSYS/README/CREDITS. *
16  *************************************************************************/
17 
18 #include "ROOT/THist.hxx"
19 #include "ROOT/TFit.hxx"
21 
22 #include <chrono>
23 #include <iostream>
24 #include <type_traits>
25 
26 long createNew(int count) {
27  long ret = 1;
28  for (int i = 0; i < count; ++i) {
29  Experimental::TH2D hist({{{100, 0., 1.}, {{0., 1., 2., 3., 10.}}}});
30  ret ^= (long)&hist;
31  }
32  return ret;
33 }
34 
35 long fillNew(int count) {
36  Experimental::TH2D hist({{{100, 0., 1.}, {{0., 1., 2., 3., 10.}}}});
37  for (int i = 0; i < count; ++i)
38  hist.Fill({0.611, 0.611});
39  return hist.GetNDim();
40 }
41 
42 long fillN(int count) {
43  Experimental::TH2D hist({{{100, 0., 1.}, {{0., 1., 2., 3., 10.}}}});
44  std::vector<std::array<double,2>> v(count);
45  for (int i = 0; i < count; ++i)
46  v[i] = {0.611, 0.611};
47  hist.FillN(v);
48  return hist.GetNDim();
49 }
50 
51 long fillBufferedNew(int count) {
52  Experimental::TH2D hist({{{100, 0., 1.}, {{0., 1., 2., 3., 10.}}}});
53  Experimental::THistBufferedFill<Experimental::TH2D> filler(hist);
54  for (int i = 0; i < count; ++i)
55  filler.Fill({0.611, 0.611});
56  return hist.GetNDim();
57 }
58 
59 using timefunc_t = std::add_pointer_t<long(int)>;
60 
61 void time1(timefunc_t run, int count, const std::string& name) {
62  using namespace std::chrono;
63  auto start = high_resolution_clock::now();
64  run(count);
65  auto end = high_resolution_clock::now();
66  duration<double> time_span = duration_cast<duration<double>>(end - start);
67 
68  std::cout << count << " * " << name << ": " << time_span.count() << "seconds \n";
69 }
70 
71 void time(timefunc_t r7, int count, const std::string& name) {
72  time1(r7, count, name + " (ROOT7)");
73 }
74 
75 void perf() {
76  time(createOld, createNew, 1000000, "create 2D hists");
77  time(fillNew, 100000000, "2D fills");
78  time(fillBufferedNew, 100000000, "2D fills (buffered)");
79 }
SVector< double, 2 > v
Definition: Dict.h:5
void run(bool only_compile=false)
Definition: run.C:1
THist< 2, double, THistStatContent, THistStatUncertainty > TH2D
Definition: THist.hxx:307
char name[80]
Definition: TGX11.cxx:109