The Gaudi Framework  master (37c0b60a)
Allocator.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ============================================================================
12 // Include file
13 // ============================================================================
14 // STD & STL
15 // ============================================================================
16 #include <algorithm>
17 #include <cmath>
18 #include <functional>
19 #include <iostream>
20 #include <random>
21 #include <string>
22 #include <vector>
23 // ============================================================================
24 // Boost
25 // ============================================================================
26 #include <boost/format.hpp>
27 // ============================================================================
28 // GaudiKernel
29 // ============================================================================
31 #include <GaudiKernel/System.h>
32 // ============================================================================
33 // Local
34 // ============================================================================
35 #include "MyClass1.h"
36 #include "MyClass1A.h"
37 // ============================================================================
38 
45 namespace {
46 
48  return stream << "U:" << ent.outputUserTime() << "\nS:" << ent.outputSystemTime()
49  << "\nE:" << ent.outputElapsedTime();
50  // return stream
51  // << "K:t/m/em/RMS:"
52  // << " " << ent.kTotalTime ()
53  // << " \t" << ent.kMeanTime ()
54  // << " \t" << ent.kMeanErrorTime ()
55  // << " \t" << ent.kRMSTime ()
56  // << std::endl
57  // << "U:t/m/em/RMS:"
58  // << " " << ent.uTotalTime ()
59  // << " \t" << ent.uMeanTime ()
60  // << " \t" << ent.uMeanErrorTime ()
61  // << " \t" << ent.uRMSTime ()
62  // << std::endl
63  // << "E:t/m/em/RMS:"
64  // << " " << ent.eTotalTime ()
65  // << " \t" << ent.eMeanTime ()
66  // << " \t" << ent.eMeanErrorTime ()
67  // << " \t" << ent.eRMSTime () ;
68  }
69 } // namespace
70 
71 namespace {
89  template <class TYPE>
90  void makeTest( const size_t number, const size_t repeat, ChronoEntity& chrono ) {
92  std::mt19937 g( rd() );
93 
94  // create an vector of pointers (FIXED length!)
95  typedef std::vector<TYPE*> Vct;
96  Vct vct = Vct( number, (TYPE*)0 );
97 
98  // sturt the loop over repetition
99  for ( size_t irep = 0; irep < repeat; ++irep ) {
100 
101  { // A) create objects
102  // - 1) start the clock
103  chrono.start();
104  // - 2) fill the vector with the data
105  for ( size_t i = 0; i < number; ++i ) { vct[i] = new TYPE(); }
106  // - 3)stop the clock
107  chrono.stop();
108  }
109 
110  { // B) reshuffle the vector to ensure the
111  // random order of destruction
112  std::shuffle( vct.begin(), vct.end(), g );
113  }
114 
115  { // C) delete objects
116  // - 1) start clock
117  chrono.start();
118  // - 2) delete the content
119  for ( size_t i = 0; i < number; ++i ) { delete vct[i]; }
120  // - 3) stop clock
121  chrono.stop();
122  }
123 
124  } // end of repetition loop
125  }
126 } // namespace
127 
128 int main() {
129 
130  const size_t number = 10000;
131  const size_t repeate = 4000;
132 
133  // normalization test with "char"
134  {
135  typedef char Test;
136 
138 
139  std::cout << " Tests with " << System::typeinfoName( typeid( Test ) ) << " size=" << sizeof( Test ) << std::endl;
140  makeTest<Test>( number, repeate, test );
141  std::cout << test << std::endl;
142  };
143 
144  // class without allocator
145  {
146  typedef MyClass1 Test;
147 
149 
150  std::cout << " Tests with " << System::typeinfoName( typeid( Test ) ) << " size=" << sizeof( Test ) << std::endl;
151  makeTest<Test>( number, repeate, test );
152  std::cout << test << std::endl;
153  };
154 
155  // class with allocator
156  {
157  typedef MyClass1A Test;
158 
160 
161  std::cout << " Tests with " << System::typeinfoName( typeid( Test ) ) << " size=" << sizeof( Test ) << std::endl;
162  makeTest<Test>( number, repeate, test );
163  std::cout << test << std::endl;
164  };
165 
166  // class without allocator
167  {
168  typedef MyClass1 Test;
169 
171 
172  std::cout << " Tests with " << System::typeinfoName( typeid( Test ) ) << " size=" << sizeof( Test ) << std::endl;
173  makeTest<Test>( number, repeate, test );
174  std::cout << test << std::endl;
175  };
176 
177  // class with allocator
178  {
179  typedef MyClass1A Test;
180 
182 
183  std::cout << " Tests with " << System::typeinfoName( typeid( Test ) ) << " size=" << sizeof( Test ) << std::endl;
184  makeTest<Test>( number, repeate, test );
185  std::cout << test << std::endl;
186  };
187 
188  return 0;
189 }
190 
191 // ============================================================================
192 // The END
193 // ============================================================================
Write.stream
stream
Definition: Write.py:32
ChronoEntity
Definition: ChronoEntity.h:31
ChronoEntity::stop
IChronoSvc::ChronoStatus stop()
stop the chrono
Definition: ChronoEntity.cpp:61
System.h
std::vector< TYPE * >
MyClass1A
Definition: MyClass1A.h:29
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:315
main
int main()
Definition: Allocator.cpp:128
ChronoEntity::start
IChronoSvc::ChronoStatus start()
start the current chrono
Definition: ChronoEntity.cpp:46
std::mt19937
ChronoEntity::outputSystemTime
std::string outputSystemTime() const
print the chrono ;
Definition: ChronoEntity.cpp:89
std::random_device
gaudirun.g
dictionary g
Definition: gaudirun.py:582
Gaudi::Parsers::operator<<
std::ostream & operator<<(std::ostream &o, const Catalog &c)
printout operator
Definition: Catalog.h:68
ChronoEntity::outputElapsedTime
std::string outputElapsedTime() const
print the chrono ;
Definition: ChronoEntity.cpp:95
std::ostream
STL class.
ChronoEntity::outputUserTime
std::string outputUserTime() const
print the chrono ;
Definition: ChronoEntity.cpp:82
Test
Definition: ViewTester.h:23
MyClass1A.h
std::endl
T endl(T... args)
ChronoEntity.h
compareRootHistos.test
test
Definition: compareRootHistos.py:28
MyClass1
Definition: MyClass1.h:29
std::shuffle
T shuffle(T... args)
MyClass1.h