1 /*=========================================================================
4 Module: $RCSfile: TestInline.cxx,v $
6 Date: $Date: 2005/11/29 13:02:44 $
7 Version: $Revision: 1.10 $
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?
34 #include <sys/times.h>
37 void frswap (double &a, double &b);
38 void fpswap (double *a, double *b);
39 inline void ifrswap(double &a, double &b);
40 inline void ifpswap(double *a, double *b);
42 uint8_t passDirect8(uint8_t a, uint8_t b);
43 uint8_t passRef8(uint8_t &a, uint8_t &b);
44 uint8_t passPtr8(uint8_t *a, uint8_t *b);
46 uint16_t passDirect16(uint16_t a, uint16_t b);
47 uint16_t passRef16(uint16_t &a, uint16_t &b);
48 uint16_t passPtr16(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);
66 void frswap(double &a, double &b)
75 void fpswap(double *a, double *b)
84 inline void ifpswap(double *a, double *b)
92 inline void ifrswap(double &a, double &b)
101 uint32_t passRef32(uint32_t &a, uint32_t &b)
105 uint32_t passPtr32(uint32_t *a, uint32_t *b)
109 uint32_t passDirect32(uint32_t a, uint32_t b)
115 uint16_t passRef16(uint16_t &a, uint16_t &b)
119 uint16_t passPtr16(uint16_t *a, uint16_t *b)
123 uint16_t passDirect16(uint16_t a, uint16_t b)
128 uint8_t passRef8(uint8_t &a, uint8_t &b)
132 uint8_t passPtr8(uint8_t *a, uint8_t *b)
136 uint8_t passDirect8(uint8_t a, uint8_t b)
141 float passRefFloat(float &a, float &b)
145 float passPtrFloat(float *a, float *b)
149 float passDirectFloat(float a, float b)
154 double passRefDouble(double &a, double &b)
158 double passPtrDouble(double *a, double *b)
162 double passDirectDouble(double a, double b)
167 int TestInline(int argc, char *argv[])
174 nbLoop = atoi(argv[1]);
179 struct tms tms1, tms2;
183 uint8_t x8 =1, y8 =2;
184 uint16_t x16=1, y16=2;
185 uint32_t x32=1, y32=2;
186 float fx =1.0f, fy=1.0f;
187 double dx =1.0 , dy=1.0;
188 // ----------------------------------------
190 std::cout << "Direct "<< std::endl;
193 for(i = 0 ; i< nbLoop ; i++)
203 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
206 // ----------------------------------------
208 std::cout << "Use a macro "<< std::endl;
211 for(i = 0 ; i< nbLoop ; i++)
218 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
221 // ----------------------------------------
223 std::cout << "Use reference function" << std::endl;
226 for(i = 0 ; i< nbLoop ; i++)
233 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
236 // ----------------------------------------
238 std::cout << "Use pointer function" << std::endl;
241 for(i = 0 ; i< nbLoop ; i++)
248 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
251 // ----------------------------------------
253 std::cout << "Use inline, main-defined reference function" << std::endl;
256 for(i = 0 ; i< nbLoop ; i++)
263 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
266 // ----------------------------------------
268 std::cout << "Use inline, main-defined pointer function" << std::endl;
271 for(i = 0 ; i< nbLoop ; i++)
278 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
281 // ----------------------------------------
283 //To check the 2 following cases, we just put the two 'static' functions
284 //hifpswap and hNoifpswap in gdcmUtil.h
286 std::cout << "Use inline, .h defined, WITH inline keyword pointer method"
291 for(i = 0 ; i< nbLoop ; i++)
293 util.hifpswap (&a, &b);
298 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
302 // ----------------------------------------
304 std::cout << "Use inline, .h defined, NO inline keyword pointer method"
308 for(i = 0 ; i< nbLoop ; i++)
310 util.hNoifpswap (&a, &b);
315 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
318 // ----------------------------------------
320 std::cout << "Use , .h defined, NO inline keyword pointer method"
324 for(i = 0 ; i< nbLoop ; i++)
326 util.hfpswap (&a, &b);
331 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
334 // ----------------------------------------
336 std::cout << "Use inline, .h defined, WITH inline keyword pointer static method"
340 for(i = 0 ; i< nbLoop ; i++)
342 gdcm::Util::sthifpswap (&a, &b);
347 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
351 // ----------------------------------------
353 std::cout << "Use inline, .h defined, NO inline keyword pointer static method"
357 for(i = 0 ; i< nbLoop ; i++)
359 gdcm::Util::sthNoifpswap (&a, &b);
364 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
368 // ----------------------------------------
370 std::cout << "Pass uint_8 param directly"
374 for(i = 0 ; i< nbLoop ; i++)
376 passDirect8 (x8, y8);
381 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
384 // ----------------------------------------
386 std::cout << "Pass uint_8 param as ref"
390 for(i = 0 ; i< nbLoop ; i++)
397 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
400 // ----------------------------------------
402 std::cout << "Pass uint_8 param as ptr"
406 for(i = 0 ; i< nbLoop ; i++)
413 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
416 // ----------------------------------------
418 std::cout << "Pass uint_16 param directly"
422 for(i = 0 ; i< nbLoop ; i++)
424 passDirect16 (x16, y16);
429 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
432 // ----------------------------------------
434 std::cout << "Pass uint_16 param as ref"
438 for(i = 0 ; i< nbLoop ; i++)
440 passRef16 (x16, y16);
445 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
448 // ----------------------------------------
450 std::cout << "Pass uint_16 param as ptr"
454 for(i = 0 ; i< nbLoop ; i++)
456 passPtr16 (&x16, &y16);
461 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
466 // ----------------------------------------
468 std::cout << "Pass uint_32 param directly"
472 for(i = 0 ; i< nbLoop ; i++)
474 passDirect32 (x32, y32);
479 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
482 // ----------------------------------------
484 std::cout << "Pass uint32_t param as ref"
488 for(i = 0 ; i< nbLoop ; i++)
490 passRef32 (x32, y32 );
495 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
498 // ----------------------------------------
500 std::cout << "Pass uint_32 param as ptr"
504 for(i = 0 ; i< nbLoop ; i++)
506 passPtr32 (&x32, &y32);
511 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
514 // ----------------------------------------
516 std::cout << "Pass float param directly"
520 for(i = 0 ; i< nbLoop ; i++)
522 passDirectFloat (fx, fy);
528 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
531 // ----------------------------------------
533 std::cout << "Pass float param as ref"
537 for(i = 0 ; i< nbLoop ; i++)
539 passRefFloat (fx, fy);
545 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
548 // ----------------------------------------
550 std::cout << "Pass float param as ptr"
554 for(i = 0 ; i< nbLoop ; i++)
556 passPtrFloat (&fx, &fy);
562 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
565 // ----------------------------------------
567 std::cout << "Pass double param directly"
571 for(i = 0 ; i< nbLoop ; i++)
573 passDirectDouble (dx, dy);
579 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
582 // ----------------------------------------
584 std::cout << "Pass double param as ref"
588 for(i = 0 ; i< nbLoop ; i++)
590 passRefDouble (dx, dy);
596 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
599 // ----------------------------------------
601 std::cout << "Pass double param as ptr"
605 for(i = 0 ; i< nbLoop ; i++)
607 passPtrDouble (&dx, &dy);
613 << (long) ((tms2.tms_utime) - (tms1.tms_utime))