1 /*=========================================================================
4 Module: $RCSfile: TestInline.cxx,v $
6 Date: $Date: 2005/10/24 01:16:20 $
7 Version: $Revision: 1.2 $
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?
33 #include "gdcmDebug.h"
37 #ifdef CMAKE_HAVE_SYS_TIMES_H
38 #include <sys/times.h>
41 void frswap (double &a, double &b);
42 void fpswap (double *a, double *b);
43 inline void ifrswap(double &a, double &b);
44 inline void ifpswap(double *a, double *b);
46 uint16_t passDirect(uint16_t a, uint16_t b);
47 uint16_t passRef(uint16_t &a, uint16_t &b);
48 uint16_t passPtr(uint16_t *a, uint16_t *b);
50 uint32_t passDirect32(uint32_t a, uint32_t b);
51 uint32_t passRef32(uint32_t &a, uint32_t &b);
52 uint32_t passPtr32(uint32_t *a, uint32_t *b);
54 double passDirect(double a, double b);
55 double passRef(double &a, double &b);
56 double passPtr(double *a, double *b);
59 //To perform a full check, just put the two 'static' functions
60 //hifpswap and hNoifpswap in a .h
62 static inline void hifpswap(double *a, double *b)
70 static void hNoifpswap(double *a, double *b)
88 void frswap(double &a, double &b)
97 void fpswap(double *a, double *b)
106 inline void ifpswap(double *a, double *b)
114 inline void ifrswap(double &a, double &b)
123 uint32_t passRef32(uint32_t &a, uint32_t &b)
127 uint32_t passPtr32(uint32_t *a, uint32_t *b)
131 uint32_t passDirect32(uint32_t a, uint32_t b)
137 uint16_t passRef(uint16_t &a, uint16_t &b)
141 uint16_t passPtr(uint16_t *a, uint16_t *b)
145 uint16_t passDirect(uint16_t a, uint16_t b)
150 double passRefDouble(double &a, double &b)
154 double passPtrDouble(double *a, double *b)
158 double passDirectDouble(double a, double b)
163 int TestInline(int argc, char *argv[])
170 nbLoop = atoi(argv[1]);
175 struct tms tms1, tms2;
181 // ----------------------------------------
183 std::cout << "Use a macro "<< std::endl;
185 for(i = 0 ; i< nbLoop ; i++)
191 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
194 // ----------------------------------------
196 std::cout << "Use reference function" << std::endl;
198 for(i = 0 ; i< nbLoop ; i++)
204 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
207 // ----------------------------------------
209 std::cout << "Use pointer function" << std::endl;
211 for(i = 0 ; i< nbLoop ; i++)
217 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
220 // ----------------------------------------
222 std::cout << "Use inline, main-defined reference function" << std::endl;
224 for(i = 0 ; i< nbLoop ; i++)
230 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
233 // ----------------------------------------
235 std::cout << "Use inline, main-defined pointer function" << std::endl;
237 for(i = 0 ; i< nbLoop ; i++)
243 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
246 // ----------------------------------------
248 //To check the 2 following cases, we just put the two 'static' functions
249 //hifpswap and hNoifpswap in gdcmUtil.h
251 std::cout << "Use inline, .h defined, WITH inline keyword pointer function"
254 for(i = 0 ; i< nbLoop ; i++)
256 gdcm::Util::hifpswap (&a, &b);
260 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
264 // ----------------------------------------
266 std::cout << "Use inline, .h defined, NO inline keyword pointer function"
269 for(i = 0 ; i< nbLoop ; i++)
271 gdcm::Util::hNoifpswap (&a, &b);
275 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
279 // ----------------------------------------
281 std::cout << "Pass uint_16 param directly"
284 for(i = 0 ; i< nbLoop ; i++)
290 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
293 // ----------------------------------------
295 std::cout << "Pass uint_16 param as ref"
298 for(i = 0 ; i< nbLoop ; i++)
304 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
307 // ----------------------------------------
309 std::cout << "Pass uint_16 param as ptr"
312 for(i = 0 ; i< nbLoop ; i++)
318 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
323 // ----------------------------------------
326 std::cout << "Pass uint_32 param directly"
329 for(i = 0 ; i< nbLoop ; i++)
335 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
338 // ----------------------------------------
340 std::cout << "Pass uint32_t param as ref"
343 for(i = 0 ; i< nbLoop ; i++)
349 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
352 // ----------------------------------------
354 std::cout << "Pass uint_32 param as ptr"
357 for(i = 0 ; i< nbLoop ; i++)
363 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
366 // ----------------------------------------
369 double dx=1.0, dy=2.0;
371 std::cout << "Pass double param directly"
374 for(i = 0 ; i< nbLoop ; i++)
376 passDirectDouble (dx, dy);
380 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
383 // ----------------------------------------
385 std::cout << "Pass double param as ref"
388 for(i = 0 ; i< nbLoop ; i++)
390 passRefDouble (dx, dy);
394 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
397 // ----------------------------------------
399 std::cout << "Pass double param as ptr"
402 for(i = 0 ; i< nbLoop ; i++)
404 passPtrDouble (&dx, &dy);
408 << (long) ((tms2.tms_utime) - (tms1.tms_utime))