1 /*=========================================================================
4 Module: $RCSfile: TestInline.cxx,v $
6 Date: $Date: 2005/11/02 09:40:11 $
7 Version: $Revision: 1.7 $
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);
68 void frswap(double &a, double &b)
77 void fpswap(double *a, double *b)
86 inline void ifpswap(double *a, double *b)
94 inline void ifrswap(double &a, double &b)
103 uint32_t passRef32(uint32_t &a, uint32_t &b)
107 uint32_t passPtr32(uint32_t *a, uint32_t *b)
111 uint32_t passDirect32(uint32_t a, uint32_t b)
117 uint16_t passRef(uint16_t &a, uint16_t &b)
121 uint16_t passPtr(uint16_t *a, uint16_t *b)
125 uint16_t passDirect(uint16_t a, uint16_t b)
130 double passRefDouble(double &a, double &b)
134 double passPtrDouble(double *a, double *b)
138 double passDirectDouble(double a, double b)
143 int TestInline(int argc, char *argv[])
150 nbLoop = atoi(argv[1]);
155 struct tms tms1, tms2;
161 // ----------------------------------------
163 std::cout << "Use a macro "<< std::endl;
165 for(i = 0 ; i< nbLoop ; i++)
171 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
174 // ----------------------------------------
176 std::cout << "Use reference function" << std::endl;
178 for(i = 0 ; i< nbLoop ; i++)
184 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
187 // ----------------------------------------
189 std::cout << "Use pointer function" << std::endl;
191 for(i = 0 ; i< nbLoop ; i++)
197 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
200 // ----------------------------------------
202 std::cout << "Use inline, main-defined reference function" << std::endl;
204 for(i = 0 ; i< nbLoop ; i++)
210 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
213 // ----------------------------------------
215 std::cout << "Use inline, main-defined pointer function" << std::endl;
217 for(i = 0 ; i< nbLoop ; i++)
223 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
226 // ----------------------------------------
228 //To check the 2 following cases, we just put the two 'static' functions
229 //hifpswap and hNoifpswap in gdcmUtil.h
231 std::cout << "Use inline, .h defined, WITH inline keyword pointer function"
234 for(i = 0 ; i< nbLoop ; i++)
236 gdcm::Util::hifpswap (&a, &b);
240 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
244 // ----------------------------------------
246 std::cout << "Use inline, .h defined, NO inline keyword pointer function"
249 for(i = 0 ; i< nbLoop ; i++)
251 gdcm::Util::hNoifpswap (&a, &b);
255 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
259 // ----------------------------------------
261 std::cout << "Pass uint_16 param directly"
264 for(i = 0 ; i< nbLoop ; i++)
270 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
273 // ----------------------------------------
275 std::cout << "Pass uint_16 param as ref"
278 for(i = 0 ; i< nbLoop ; i++)
284 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
287 // ----------------------------------------
289 std::cout << "Pass uint_16 param as ptr"
292 for(i = 0 ; i< nbLoop ; i++)
298 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
303 // ----------------------------------------
306 std::cout << "Pass uint_32 param directly"
309 for(i = 0 ; i< nbLoop ; i++)
315 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
318 // ----------------------------------------
320 std::cout << "Pass uint32_t param as ref"
323 for(i = 0 ; i< nbLoop ; i++)
329 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
332 // ----------------------------------------
334 std::cout << "Pass uint_32 param as ptr"
337 for(i = 0 ; i< nbLoop ; i++)
343 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
346 // ----------------------------------------
349 double dx=1.0, dy=2.0;
351 std::cout << "Pass double param directly"
354 for(i = 0 ; i< nbLoop ; i++)
356 passDirectDouble (dx, dy);
360 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
363 // ----------------------------------------
365 std::cout << "Pass double param as ref"
368 for(i = 0 ; i< nbLoop ; i++)
370 passRefDouble (dx, dy);
374 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
377 // ----------------------------------------
379 std::cout << "Pass double param as ptr"
382 for(i = 0 ; i< nbLoop ; i++)
384 passPtrDouble (&dx, &dy);
388 << (long) ((tms2.tms_utime) - (tms1.tms_utime))