1 /*=========================================================================
4 Module: $RCSfile: TestInline.cxx,v $
6 Date: $Date: 2005/10/24 13:17:22 $
7 Version: $Revision: 1.4 $
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>
40 #include <sys/timeb.h>
43 void frswap (double &a, double &b);
44 void fpswap (double *a, double *b);
45 inline void ifrswap(double &a, double &b);
46 inline void ifpswap(double *a, double *b);
48 uint16_t passDirect(uint16_t a, uint16_t b);
49 uint16_t passRef(uint16_t &a, uint16_t &b);
50 uint16_t passPtr(uint16_t *a, uint16_t *b);
52 uint32_t passDirect32(uint32_t a, uint32_t b);
53 uint32_t passRef32(uint32_t &a, uint32_t &b);
54 uint32_t passPtr32(uint32_t *a, uint32_t *b);
56 double passDirect(double a, double b);
57 double passRef(double &a, double &b);
58 double passPtr(double *a, double *b);
61 //To perform a full check, just put the two 'static' functions
62 //hifpswap and hNoifpswap in a .h
64 static inline void hifpswap(double *a, double *b)
72 static void hNoifpswap(double *a, double *b)
90 void frswap(double &a, double &b)
99 void fpswap(double *a, double *b)
108 inline void ifpswap(double *a, double *b)
116 inline void ifrswap(double &a, double &b)
125 uint32_t passRef32(uint32_t &a, uint32_t &b)
129 uint32_t passPtr32(uint32_t *a, uint32_t *b)
133 uint32_t passDirect32(uint32_t a, uint32_t b)
139 uint16_t passRef(uint16_t &a, uint16_t &b)
143 uint16_t passPtr(uint16_t *a, uint16_t *b)
147 uint16_t passDirect(uint16_t a, uint16_t b)
152 double passRefDouble(double &a, double &b)
156 double passPtrDouble(double *a, double *b)
160 double passDirectDouble(double a, double b)
165 int TestInline(int argc, char *argv[])
172 nbLoop = atoi(argv[1]);
177 struct tms tms1, tms2;
183 // ----------------------------------------
185 std::cout << "Use a macro "<< std::endl;
187 for(i = 0 ; i< nbLoop ; i++)
193 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
196 // ----------------------------------------
198 std::cout << "Use reference function" << std::endl;
200 for(i = 0 ; i< nbLoop ; i++)
206 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
209 // ----------------------------------------
211 std::cout << "Use pointer function" << std::endl;
213 for(i = 0 ; i< nbLoop ; i++)
219 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
222 // ----------------------------------------
224 std::cout << "Use inline, main-defined reference function" << std::endl;
226 for(i = 0 ; i< nbLoop ; i++)
232 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
235 // ----------------------------------------
237 std::cout << "Use inline, main-defined pointer function" << std::endl;
239 for(i = 0 ; i< nbLoop ; i++)
245 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
248 // ----------------------------------------
250 //To check the 2 following cases, we just put the two 'static' functions
251 //hifpswap and hNoifpswap in gdcmUtil.h
253 std::cout << "Use inline, .h defined, WITH inline keyword pointer function"
256 for(i = 0 ; i< nbLoop ; i++)
258 gdcm::Util::hifpswap (&a, &b);
262 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
266 // ----------------------------------------
268 std::cout << "Use inline, .h defined, NO inline keyword pointer function"
271 for(i = 0 ; i< nbLoop ; i++)
273 gdcm::Util::hNoifpswap (&a, &b);
277 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
281 // ----------------------------------------
283 std::cout << "Pass uint_16 param directly"
286 for(i = 0 ; i< nbLoop ; i++)
292 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
295 // ----------------------------------------
297 std::cout << "Pass uint_16 param as ref"
300 for(i = 0 ; i< nbLoop ; i++)
306 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
309 // ----------------------------------------
311 std::cout << "Pass uint_16 param as ptr"
314 for(i = 0 ; i< nbLoop ; i++)
320 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
325 // ----------------------------------------
328 std::cout << "Pass uint_32 param directly"
331 for(i = 0 ; i< nbLoop ; i++)
337 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
340 // ----------------------------------------
342 std::cout << "Pass uint32_t param as ref"
345 for(i = 0 ; i< nbLoop ; i++)
351 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
354 // ----------------------------------------
356 std::cout << "Pass uint_32 param as ptr"
359 for(i = 0 ; i< nbLoop ; i++)
365 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
368 // ----------------------------------------
371 double dx=1.0, dy=2.0;
373 std::cout << "Pass double param directly"
376 for(i = 0 ; i< nbLoop ; i++)
378 passDirectDouble (dx, dy);
382 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
385 // ----------------------------------------
387 std::cout << "Pass double param as ref"
390 for(i = 0 ; i< nbLoop ; i++)
392 passRefDouble (dx, dy);
396 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
399 // ----------------------------------------
401 std::cout << "Pass double param as ptr"
404 for(i = 0 ; i< nbLoop ; i++)
406 passPtrDouble (&dx, &dy);
410 << (long) ((tms2.tms_utime) - (tms1.tms_utime))