1 /*=========================================================================
4 Module: $RCSfile: exInline.cxx,v $
6 Date: $Date: 2005/10/21 08:43:31 $
7 Version: $Revision: 1.1 $
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[])
88 nbLoop = atoi(argv[1]);
93 struct tms tms1, tms2;
97 // ----------------------------------------
99 std::cout << "Use a macro "<< std::endl;
101 for(i = 0 ; i< nbLoop ; i++)
107 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
110 // ----------------------------------------
112 std::cout << "Use reference function" << std::endl;
114 for(i = 0 ; i< nbLoop ; i++)
120 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
123 // ----------------------------------------
125 std::cout << "Use pointer function" << std::endl;
127 for(i = 0 ; i< nbLoop ; i++)
133 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
136 // ----------------------------------------
138 std::cout << "Use inline, main-defined reference function" << std::endl;
140 for(i = 0 ; i< nbLoop ; i++)
146 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
149 // ----------------------------------------
151 std::cout << "Use inline, main-defined pointer function" << std::endl;
153 for(i = 0 ; i< nbLoop ; i++)
159 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
163 //To check the 2 following cases, just put the two 'static' functions
164 //hifpswap and hNoifpswap in a .h
166 static inline void hifpswap(double *a, double *b)
174 static void hNoifpswap(double *a, double *b)
182 // ----------------------------------------
184 std::cout << "Use inline, .h defined, WITH inline keyword pointer function"
187 for(i = 0 ; i< nbLoop ; i++)
189 gdcm::Util::hifpswap (&a, &b);
193 << (long) ((tms2.tms_utime) - (tms1.tms_utime))
197 // ----------------------------------------
199 std::cout << "Use inline, .h defined, NO inline keyword pointer function"
202 for(i = 0 ; i< nbLoop ; i++)
204 gdcm::Util::hNoifpswap (&a, &b);
208 << (long) ((tms2.tms_utime) - (tms1.tms_utime))