The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
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
// ============================================================================
30
#include <
GaudiKernel/ChronoEntity.h
>
31
#include <
GaudiKernel/System.h
>
32
// ============================================================================
33
// Local
34
// ============================================================================
35
#include "
MyClass1.h
"
36
#include "
MyClass1A.h
"
37
// ============================================================================
38
44
45
namespace
{
46
47
std::ostream&
operator<<
( std::ostream& stream,
const
ChronoEntity
& ent ) {
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 ) {
91
std::random_device rd;
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
137
ChronoEntity
test;
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
148
ChronoEntity
test;
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
159
ChronoEntity
test;
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
170
ChronoEntity
test;
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
181
ChronoEntity
test;
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
// ============================================================================
operator<<
std::ostream & operator<<(std::ostream &s, AlgsExecutionStates::State x)
Streaming of State values.
Definition
AlgsExecutionStates.h:99
main
int main()
Definition
Allocator.cpp:128
ChronoEntity.h
MyClass1.h
MyClass1A.h
System.h
ChronoEntity
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition
ChronoEntity.h:26
ChronoEntity::outputSystemTime
std::string outputSystemTime() const
print the chrono ;
Definition
ChronoEntity.cpp:72
ChronoEntity::start
IChronoSvc::ChronoStatus start()
start the current chrono
Definition
ChronoEntity.cpp:35
ChronoEntity::stop
IChronoSvc::ChronoStatus stop()
stop the chrono
Definition
ChronoEntity.cpp:50
ChronoEntity::outputElapsedTime
std::string outputElapsedTime() const
print the chrono ;
Definition
ChronoEntity.cpp:76
ChronoEntity::outputUserTime
std::string outputUserTime() const
print the chrono ;
Definition
ChronoEntity.cpp:68
MyClass1A
Simple class, equipped with "Allocator", to be compared with class MyClass1.
Definition
MyClass1A.h:28
MyClass1
Trivial "almost empty" class.
Definition
MyClass1.h:28
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition
System.cpp:254
Test
Definition
ViewTester.h:25
Write.stream
stream
Definition
Write.py:32
gaudirun.g
dict g
Definition
gaudirun.py:590
GaudiTestSuite
src
Allocator
Allocator.cpp
Generated on
for The Gaudi Framework by
1.17.0