1 /*=========================================================================
4 Module: $RCSfile: TestInline.cxx,v $
6 Date: $Date: 2005/11/17 17:44:24 $
7 Version: $Revision: 1.8 $
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 "TestInLine.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;
166 for(i = 0 ; i< nbLoop ; i++)
173 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
176 // ----------------------------------------
178 std::cout << "Use reference function" << std::endl;
181 for(i = 0 ; i< nbLoop ; i++)
188 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
191 // ----------------------------------------
193 std::cout << "Use pointer function" << std::endl;
196 for(i = 0 ; i< nbLoop ; i++)
203 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
206 // ----------------------------------------
208 std::cout << "Use inline, main-defined reference function" << std::endl;
211 for(i = 0 ; i< nbLoop ; i++)
218 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
221 // ----------------------------------------
223 std::cout << "Use inline, main-defined pointer function" << std::endl;
226 for(i = 0 ; i< nbLoop ; i++)
233 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
236 // ----------------------------------------
238 //To check the 2 following cases, we just put the two 'static' functions
239 //hifpswap and hNoifpswap in gdcmUtil.h
241 std::cout << "Use inline, .h defined, WITH inline keyword pointer function"
245 for(i = 0 ; i< nbLoop ; i++)
247 //gdcm::Util::hifpswap (&a, &b);
253 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
257 // ----------------------------------------
259 std::cout << "Use inline, .h defined, NO inline keyword pointer function"
263 for(i = 0 ; i< nbLoop ; i++)
265 //gdcm::Util::hNoifpswap (&a, &b);
271 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
275 // ----------------------------------------
277 std::cout << "Pass uint_16 param directly"
281 for(i = 0 ; i< nbLoop ; i++)
288 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
291 // ----------------------------------------
293 std::cout << "Pass uint_16 param as ref"
297 for(i = 0 ; i< nbLoop ; i++)
304 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
307 // ----------------------------------------
309 std::cout << "Pass uint_16 param as ptr"
313 for(i = 0 ; i< nbLoop ; i++)
320 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
325 // ----------------------------------------
328 std::cout << "Pass uint_32 param directly"
332 for(i = 0 ; i< nbLoop ; i++)
339 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
342 // ----------------------------------------
344 std::cout << "Pass uint32_t param as ref"
348 for(i = 0 ; i< nbLoop ; i++)
355 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
358 // ----------------------------------------
360 std::cout << "Pass uint_32 param as ptr"
364 for(i = 0 ; i< nbLoop ; i++)
371 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
374 // ----------------------------------------
377 double dx=1.0, dy=2.0;
379 std::cout << "Pass double param directly"
383 for(i = 0 ; i< nbLoop ; i++)
385 passDirectDouble (dx, dy);
391 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
394 // ----------------------------------------
396 std::cout << "Pass double param as ref"
400 for(i = 0 ; i< nbLoop ; i++)
402 passRefDouble (dx, dy);
408 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
411 // ----------------------------------------
413 std::cout << "Pass double param as ptr"
417 for(i = 0 ; i< nbLoop ; i++)
419 passPtrDouble (&dx, &dy);
425 << (long) ((tms2.tms_utime) - (tms1.tms_utime))