1 /*=========================================================================
4 Module: $RCSfile: TestInline.cxx,v $
6 Date: $Date: 2005/10/23 14:49:51 $
7 Version: $Revision: 1.1 $
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 #include <sys/times.h>
39 void frswap (double &a, double &b);
40 void fpswap (double *a, double *b);
41 inline void ifrswap(double &a, double &b);
42 inline void ifpswap(double *a, double *b);
44 uint16_t passDirect(uint16_t a, uint16_t b);
45 uint16_t passRef(uint16_t &a, uint16_t &b);
46 uint16_t passPtr(uint16_t *a, uint16_t *b);
48 uint32_t passDirect32(uint32_t a, uint32_t b);
49 uint32_t passRef32(uint32_t &a, uint32_t &b);
50 uint32_t passPtr32(uint32_t *a, uint32_t *b);
52 double passDirect(double a, double b);
53 double passRef(double &a, double &b);
54 double passPtr(double *a, double *b);
57 //To perform a full check, just put the two 'static' functions
58 //hifpswap and hNoifpswap in a .h
60 static inline void hifpswap(double *a, double *b)
68 static void hNoifpswap(double *a, double *b)
86 void frswap(double &a, double &b)
95 void fpswap(double *a, double *b)
104 inline void ifpswap(double *a, double *b)
112 inline void ifrswap(double &a, double &b)
121 uint32_t passRef32(uint32_t &a, uint32_t &b)
125 uint32_t passPtr32(uint32_t *a, uint32_t *b)
129 uint32_t passDirect32(uint32_t a, uint32_t b)
135 uint16_t passRef(uint16_t &a, uint16_t &b)
139 uint16_t passPtr(uint16_t *a, uint16_t *b)
143 uint16_t passDirect(uint16_t a, uint16_t b)
148 double passRefDouble(double &a, double &b)
152 double passPtrDouble(double *a, double *b)
156 double passDirectDouble(double a, double b)
161 int TestInline(int argc, char *argv[])
168 nbLoop = atoi(argv[1]);
173 struct tms tms1, tms2;
179 // ----------------------------------------
181 std::cout << "Use a macro "<< std::endl;
183 for(i = 0 ; i< nbLoop ; i++)
189 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
192 // ----------------------------------------
194 std::cout << "Use reference function" << std::endl;
196 for(i = 0 ; i< nbLoop ; i++)
202 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
205 // ----------------------------------------
207 std::cout << "Use pointer function" << std::endl;
209 for(i = 0 ; i< nbLoop ; i++)
215 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
218 // ----------------------------------------
220 std::cout << "Use inline, main-defined reference function" << std::endl;
222 for(i = 0 ; i< nbLoop ; i++)
228 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
231 // ----------------------------------------
233 std::cout << "Use inline, main-defined pointer function" << std::endl;
235 for(i = 0 ; i< nbLoop ; i++)
241 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
244 // ----------------------------------------
246 //To check the 2 following cases, we just put the two 'static' functions
247 //hifpswap and hNoifpswap in gdcmUtil.h
249 std::cout << "Use inline, .h defined, WITH inline keyword pointer function"
252 for(i = 0 ; i< nbLoop ; i++)
254 gdcm::Util::hifpswap (&a, &b);
258 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
262 // ----------------------------------------
264 std::cout << "Use inline, .h defined, NO inline keyword pointer function"
267 for(i = 0 ; i< nbLoop ; i++)
269 gdcm::Util::hNoifpswap (&a, &b);
273 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
277 // ----------------------------------------
279 std::cout << "Pass uint_16 param directly"
282 for(i = 0 ; i< nbLoop ; i++)
288 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
291 // ----------------------------------------
293 std::cout << "Pass uint_16 param as ref"
296 for(i = 0 ; i< nbLoop ; i++)
302 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
305 // ----------------------------------------
307 std::cout << "Pass uint_16 param as ptr"
310 for(i = 0 ; i< nbLoop ; i++)
316 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
321 // ----------------------------------------
324 std::cout << "Pass uint_32 param directly"
327 for(i = 0 ; i< nbLoop ; i++)
333 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
336 // ----------------------------------------
338 std::cout << "Pass uint32_t param as ref"
341 for(i = 0 ; i< nbLoop ; i++)
347 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
350 // ----------------------------------------
352 std::cout << "Pass uint_32 param as ptr"
355 for(i = 0 ; i< nbLoop ; i++)
361 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
364 // ----------------------------------------
367 double dx=1.0, dy=2.0;
369 std::cout << "Pass double param directly"
372 for(i = 0 ; i< nbLoop ; i++)
374 passDirectDouble (dx, dy);
378 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
381 // ----------------------------------------
383 std::cout << "Pass double param as ref"
386 for(i = 0 ; i< nbLoop ; i++)
388 passRefDouble (dx, dy);
392 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
395 // ----------------------------------------
397 std::cout << "Pass double param as ptr"
400 for(i = 0 ; i< nbLoop ; i++)
402 passPtrDouble (&dx, &dy);
406 << (long) ((tms2.tms_utime) - (tms1.tms_utime))