X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestInline.cxx;h=774830a3ec445199d45b3421e6e35867a8e2c372;hb=f540ed5835e7b89478e6048a577d494c0e156f2a;hp=38611daeb098edf45a07a991d05c3b220a23c72f;hpb=c556c62e38ad8f5b0423a91d919c13ac85a23f32;p=gdcm.git diff --git a/Testing/TestInline.cxx b/Testing/TestInline.cxx index 38611dae..774830a3 100755 --- a/Testing/TestInline.cxx +++ b/Testing/TestInline.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestInline.cxx,v $ Language: C++ - Date: $Date: 2005/11/02 09:40:11 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/11/30 11:40:26 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -30,24 +30,22 @@ // Which CXX_FLAGS, LINKER_FLAGS, ..., must we set to see the difference? #include "gdcmUtil.h" -#include "gdcmDebug.h" -#include -#include -#ifdef CMAKE_HAVE_SYS_TIMES_H #include -#else -#include -#endif +#include void frswap (double &a, double &b); void fpswap (double *a, double *b); inline void ifrswap(double &a, double &b); inline void ifpswap(double *a, double *b); -uint16_t passDirect(uint16_t a, uint16_t b); -uint16_t passRef(uint16_t &a, uint16_t &b); -uint16_t passPtr(uint16_t *a, uint16_t *b); +uint8_t passDirect8(uint8_t a, uint8_t b); +uint8_t passRef8(uint8_t &a, uint8_t &b); +uint8_t passPtr8(uint8_t *a, uint8_t *b); + +uint16_t passDirect16(uint16_t a, uint16_t b); +uint16_t passRef16(uint16_t &a, uint16_t &b); +uint16_t passPtr16(uint16_t *a, uint16_t *b); uint32_t passDirect32(uint32_t a, uint32_t b); uint32_t passRef32(uint32_t &a, uint32_t &b); @@ -57,12 +55,12 @@ double passDirect(double a, double b); double passRef(double &a, double &b); double passPtr(double *a, double *b); -#define \ -mswap(a, b) \ -{ \ - tmp = a; \ - a = b; \ - b = tmp; \ +#define \ +mswap(a, b) \ +{ \ + double tmp = a;\ + a = b; \ + b = tmp; \ } void frswap(double &a, double &b) @@ -114,15 +112,41 @@ uint32_t passDirect32(uint32_t a, uint32_t b) } -uint16_t passRef(uint16_t &a, uint16_t &b) +uint16_t passRef16(uint16_t &a, uint16_t &b) +{ + return a + b; +} +uint16_t passPtr16(uint16_t *a, uint16_t *b) +{ + return *a + *b; +} +uint16_t passDirect16(uint16_t a, uint16_t b) +{ + return a + b; +} + +uint8_t passRef8(uint8_t &a, uint8_t &b) +{ + return a + b; +} +uint8_t passPtr8(uint8_t *a, uint8_t *b) +{ + return *a + *b; +} +uint8_t passDirect8(uint8_t a, uint8_t b) +{ + return a + b; +} + +float passRefFloat(float &a, float &b) { return a + b; } -uint16_t passPtr(uint16_t *a, uint16_t *b) +float passPtrFloat(float *a, float *b) { return *a + *b; } -uint16_t passDirect(uint16_t a, uint16_t b) +float passDirectFloat(float a, float b) { return a + b; } @@ -143,43 +167,76 @@ double passDirectDouble(double a, double b) int TestInline(int argc, char *argv[]) { + // just to know, on every proc + std::cout << "Size of short int " << sizeof(short int) << std::endl; + std::cout << "Size of int " << sizeof(int) << std::endl; + std::cout << "Size of long " << sizeof(long) << std::endl; + std::cout << "Size of float" << sizeof(float) << std::endl; + std::cout << "Size of double" << sizeof(double) << std::endl; + std::cout << "Size of int* " << sizeof(int*) << std::endl; + std::cout << "-----------------" << std::endl; unsigned int nbLoop; unsigned int i; if (argc > 1) nbLoop = atoi(argv[1]); else - nbLoop = 10000000; + nbLoop = 10000000; - clock_t r1, r2; + //clock_t r1, r2; struct tms tms1, tms2; double a = 1, b = 2; - double tmp; - uint16_t x=1, y=2; + uint8_t x8 =1, y8 =2; + uint16_t x16=1, y16=2; + uint32_t x32=1, y32=2; + float fx =1.0f, fy=1.0f; + double dx =1.0 , dy=1.0; + // ---------------------------------------- + + std::cout << "Direct "<< std::endl; + //r1 = times(&tms1); + times(&tms1); + for(i = 0 ; i< nbLoop ; i++) + { + double tmp; + tmp=a; + a=b; + b=tmp; + } + //r2 = times(&tms2); + times(&tms2); + std::cout + << (long) ((tms2.tms_utime) - (tms1.tms_utime)) + << std::endl; + // ---------------------------------------- std::cout << "Use a macro "<< std::endl; - r1 = times(&tms1); + //r1 = times(&tms1); + times(&tms1); for(i = 0 ; i< nbLoop ; i++) { mswap (a,b); } - r2 = times(&tms2); - std::cout + //r2 = times(&tms2); + times(&tms2); + std::cout << (long) ((tms2.tms_utime) - (tms1.tms_utime)) << std::endl; // ---------------------------------------- std::cout << "Use reference function" << std::endl; - r1 = times(&tms1); - for(i = 0 ; i< nbLoop ; i++) + //r1 = times(&tms1); + times(&tms1); + for(i = 0 ; i< nbLoop ; i++) { frswap (a,b); } - r2 = times(&tms2); + //r2 = times(&tms2); + times(&tms2); std::cout << (long) ((tms2.tms_utime) - (tms1.tms_utime)) << std::endl; @@ -187,12 +244,14 @@ int TestInline(int argc, char *argv[]) // ---------------------------------------- std::cout << "Use pointer function" << std::endl; - r1 = times(&tms1); - for(i = 0 ; i< nbLoop ; i++) + //r1 = times(&tms1); + times(&tms1); + for(i = 0 ; i< nbLoop ; i++) { fpswap (&a, &b); } - r2 = times(&tms2); + //r2 = times(&tms2); + times(&tms2); std::cout << (long) ((tms2.tms_utime) - (tms1.tms_utime)) << std::endl; @@ -200,12 +259,14 @@ int TestInline(int argc, char *argv[]) // ---------------------------------------- std::cout << "Use inline, main-defined reference function" << std::endl; - r1 = times(&tms1); - for(i = 0 ; i< nbLoop ; i++) + //r1 = times(&tms1); + times(&tms1); + for(i = 0 ; i< nbLoop ; i++) { ifrswap (a, b); } - r2 = times(&tms2); + //r2 = times(&tms2); + times(&tms2); std::cout << (long) ((tms2.tms_utime) - (tms1.tms_utime)) << std::endl; @@ -213,12 +274,14 @@ int TestInline(int argc, char *argv[]) // ---------------------------------------- std::cout << "Use inline, main-defined pointer function" << std::endl; - r1 = times(&tms1); - for(i = 0 ; i< nbLoop ; i++) + //r1 = times(&tms1); + times(&tms1); + for(i = 0 ; i< nbLoop ; i++) { ifpswap (&a, &b); } - r2 = times(&tms2); + //r2 = times(&tms2); + times(&tms2); std::cout << (long) ((tms2.tms_utime) - (tms1.tms_utime)) << std::endl; @@ -228,14 +291,17 @@ int TestInline(int argc, char *argv[]) //To check the 2 following cases, we just put the two 'static' functions //hifpswap and hNoifpswap in gdcmUtil.h - std::cout << "Use inline, .h defined, WITH inline keyword pointer function" + std::cout << "Use inline, .h defined, WITH inline keyword pointer method" << std::endl; - r1 = times(&tms1); - for(i = 0 ; i< nbLoop ; i++) + //r1 = times(&tms1); + gdcm::Util util; + times(&tms1); + for(i = 0 ; i< nbLoop ; i++) { - gdcm::Util::hifpswap (&a, &b); + util.hifpswap (&a, &b); } - r2 = times(&tms2); + //r2 = times(&tms2); + times(&tms2); std::cout << (long) ((tms2.tms_utime) - (tms1.tms_utime)) << std::endl; @@ -243,29 +309,130 @@ int TestInline(int argc, char *argv[]) // ---------------------------------------- - std::cout << "Use inline, .h defined, NO inline keyword pointer function" + std::cout << "Use inline, .h defined, NO inline keyword pointer method" << std::endl; - r1 = times(&tms1); - for(i = 0 ; i< nbLoop ; i++) + //r1 = times(&tms1); + times(&tms1); + for(i = 0 ; i< nbLoop ; i++) + { + util.hNoifpswap (&a, &b); + } + //r2 = times(&tms2); + times(&tms2); + std::cout + << (long) ((tms2.tms_utime) - (tms1.tms_utime)) + << std::endl; + + // ---------------------------------------- + + std::cout << "Use , .h defined, NO inline keyword pointer method" + << std::endl; + //r1 = times(&tms1); + times(&tms1); + for(i = 0 ; i< nbLoop ; i++) + { + util.hfpswap (&a, &b); + } + //r2 = times(&tms2); + times(&tms2); + std::cout + << (long) ((tms2.tms_utime) - (tms1.tms_utime)) + <