1 /*=========================================================================
4 Module: $RCSfile: TestInline.cxx,v $
6 Date: $Date: 2005/11/18 11:46:37 $
7 Version: $Revision: 1.9 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 // This test is expected to 'show' the actual effect on an 'inline' function.
19 // We exchange 2 numbers
20 // - with a macro : this is the quicker (any doubt ?)
21 // - with a function, passing the params by pointer
22 // - with a function, passing the params by reference (exactly same time)
23 // - with an inline function described in the main()
24 // absolutely NO effect ?!?
25 // - with a function, described in the .h
26 // absolutely NO effect ?!?
27 // - with an inline function, described in the .h
28 // absolutely NO effect ?!?
30 // Which CXX_FLAGS, LINKER_FLAGS, ..., must we set to see the difference?
36 void frswap (double &a, double &b);
37 void fpswap (double *a, double *b);
38 inline void ifrswap(double &a, double &b);
39 inline void ifpswap(double *a, double *b);
41 uint16_t passDirect(uint16_t a, uint16_t b);
42 uint16_t passRef(uint16_t &a, uint16_t &b);
43 uint16_t passPtr(uint16_t *a, uint16_t *b);
45 uint32_t passDirect32(uint32_t a, uint32_t b);
46 uint32_t passRef32(uint32_t &a, uint32_t &b);
47 uint32_t passPtr32(uint32_t *a, uint32_t *b);
49 double passDirect(double a, double b);
50 double passRef(double &a, double &b);
51 double passPtr(double *a, double *b);
61 void frswap(double &a, double &b)
70 void fpswap(double *a, double *b)
79 inline void ifpswap(double *a, double *b)
87 inline void ifrswap(double &a, double &b)
96 uint32_t passRef32(uint32_t &a, uint32_t &b)
100 uint32_t passPtr32(uint32_t *a, uint32_t *b)
104 uint32_t passDirect32(uint32_t a, uint32_t b)
110 uint16_t passRef(uint16_t &a, uint16_t &b)
114 uint16_t passPtr(uint16_t *a, uint16_t *b)
118 uint16_t passDirect(uint16_t a, uint16_t b)
123 double passRefDouble(double &a, double &b)
127 double passPtrDouble(double *a, double *b)
131 double passDirectDouble(double a, double b)
136 int TestInline(int argc, char *argv[])
143 nbLoop = atoi(argv[1]);
148 struct tms tms1, tms2;
154 // ----------------------------------------
156 std::cout << "Use a macro "<< std::endl;
159 for(i = 0 ; i< nbLoop ; i++)
166 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
169 // ----------------------------------------
171 std::cout << "Use reference function" << std::endl;
174 for(i = 0 ; i< nbLoop ; i++)
181 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
184 // ----------------------------------------
186 std::cout << "Use pointer function" << std::endl;
189 for(i = 0 ; i< nbLoop ; i++)
196 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
199 // ----------------------------------------
201 std::cout << "Use inline, main-defined reference function" << std::endl;
204 for(i = 0 ; i< nbLoop ; i++)
211 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
214 // ----------------------------------------
216 std::cout << "Use inline, main-defined pointer function" << std::endl;
219 for(i = 0 ; i< nbLoop ; i++)
226 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
229 // ----------------------------------------
231 //To check the 2 following cases, we just put the two 'static' functions
232 //hifpswap and hNoifpswap in gdcmUtil.h
234 std::cout << "Use inline, .h defined, WITH inline keyword pointer function"
238 for(i = 0 ; i< nbLoop ; i++)
240 //gdcm::Util::hifpswap (&a, &b);
246 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
250 // ----------------------------------------
252 std::cout << "Use inline, .h defined, NO inline keyword pointer function"
256 for(i = 0 ; i< nbLoop ; i++)
258 //gdcm::Util::hNoifpswap (&a, &b);
264 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
268 // ----------------------------------------
270 std::cout << "Pass uint_16 param directly"
274 for(i = 0 ; i< nbLoop ; i++)
281 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
284 // ----------------------------------------
286 std::cout << "Pass uint_16 param as ref"
290 for(i = 0 ; i< nbLoop ; i++)
297 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
300 // ----------------------------------------
302 std::cout << "Pass uint_16 param as ptr"
306 for(i = 0 ; i< nbLoop ; i++)
313 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
318 // ----------------------------------------
321 std::cout << "Pass uint_32 param directly"
325 for(i = 0 ; i< nbLoop ; i++)
332 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
335 // ----------------------------------------
337 std::cout << "Pass uint32_t param as ref"
341 for(i = 0 ; i< nbLoop ; i++)
348 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
351 // ----------------------------------------
353 std::cout << "Pass uint_32 param as ptr"
357 for(i = 0 ; i< nbLoop ; i++)
364 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
367 // ----------------------------------------
370 double dx=1.0, dy=2.0;
372 std::cout << "Pass double param directly"
376 for(i = 0 ; i< nbLoop ; i++)
378 passDirectDouble (dx, dy);
384 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
387 // ----------------------------------------
389 std::cout << "Pass double param as ref"
393 for(i = 0 ; i< nbLoop ; i++)
395 passRefDouble (dx, dy);
401 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
404 // ----------------------------------------
406 std::cout << "Pass double param as ptr"
410 for(i = 0 ; i< nbLoop ; i++)
412 passPtrDouble (&dx, &dy);
418 << (long) ((tms2.tms_utime) - (tms1.tms_utime))