1 /*=========================================================================
4 Module: $RCSfile: exInline.cxx,v $
6 Date: $Date: 2007/06/21 15:01:00 $
7 Version: $Revision: 1.3 $
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 (anny 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() : absolutely NO effect ?!?
24 // - with an inline function described in the .h : absolutely NO effect ?!?
26 // Must we ask optimization to see the difference?
29 #include "gdcmDebug.h"
33 #include <sys/times.h>
35 void frswap (double &a, double &b);
36 void fpswap (double *a, double *b);
37 inline void ifrswap(double &a, double &b);
38 inline void ifpswap(double *a, double *b);
49 void frswap(double &a, double &b)
58 void fpswap(double *a, double *b)
67 inline void ifpswap(double *a, double *b)
75 inline void ifrswap(double &a, double &b)
83 int main(int argc, char *argv[])
86 uint32_t a1 = 0xfedcba98;
88 std::cout<< "sizeof(uint32_t) " << sizeof(uint32_t)
89 << " sizeof(uint64_t) " << sizeof(uint64_t) << std::endl;
91 std::cout<< std::hex <<a1 << " " << b1 << std::endl;
93 uint64_t b2= 0x76543210;
95 std::cout<< std::hex <<b1 << " " << b2 << std::endl;
99 nbLoop = atoi(argv[1]);
104 struct tms tms1, tms2;
108 // ----------------------------------------
110 std::cout << "Use a macro "<< std::endl;
112 for(i = 0 ; i< nbLoop ; i++)
118 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
121 // ----------------------------------------
123 std::cout << "Use reference function" << std::endl;
125 for(i = 0 ; i< nbLoop ; i++)
131 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
134 // ----------------------------------------
136 std::cout << "Use pointer function" << std::endl;
138 for(i = 0 ; i< nbLoop ; i++)
144 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
147 // ----------------------------------------
149 std::cout << "Use inline, main-defined reference function" << std::endl;
151 for(i = 0 ; i< nbLoop ; i++)
157 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
160 // ----------------------------------------
162 std::cout << "Use inline, main-defined pointer function" << std::endl;
164 for(i = 0 ; i< nbLoop ; i++)
170 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
174 //To check the 2 following cases, just put the two 'static' functions
175 //hifpswap and hNoifpswap in a .h
177 static inline void hifpswap(double *a, double *b)
185 static void hNoifpswap(double *a, double *b)
193 // ----------------------------------------
195 std::cout << "Use inline, .h defined, WITH inline keyword pointer function"
198 for(i = 0 ; i< nbLoop ; i++)
200 GDCM_NAME_SPACE::Util::hifpswap (&a, &b);
204 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
208 // ----------------------------------------
210 std::cout << "Use inline, .h defined, NO inline keyword pointer function"
213 for(i = 0 ; i< nbLoop ; i++)
215 GDCM_NAME_SPACE::Util::hNoifpswap (&a, &b);
219 << (long) ((tms2.tms_utime) - (tms1.tms_utime))