From cd43889882cab529a00c3d74dafb88406baa9be7 Mon Sep 17 00:00:00 2001 From: jpr Date: Fri, 21 Sep 2007 13:34:09 +0000 Subject: [PATCH] Just to see, on the Dashbord (Linux+Windows) whether inline has an effect or not. (not any, on by PC ...) --- Testing/CMakeLists.txt | 4 +- Testing/TestInline.cxx | 601 +++++++++++++++++++---------------------- 2 files changed, 275 insertions(+), 330 deletions(-) diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 8a279fec..5f7fcefd 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -25,11 +25,11 @@ SET(TEST_SOURCES TestEnumVR.cxx TestBuildUpDicomDir.cxx # writes a file named "NewDICOMDIR" ) -IF(UNIX) +IF(UNIX OR WIN32) SET(TEST_SOURCES ${TEST_SOURCES} TestInline.cxx ) -ENDIF(UNIX) +ENDIF(UNIX OR WIN32) # add tests that require data IF (GDCM_DATA_ROOT) diff --git a/Testing/TestInline.cxx b/Testing/TestInline.cxx index 5b3bcf9e..669c0ea5 100755 --- a/Testing/TestInline.cxx +++ b/Testing/TestInline.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestInline.cxx,v $ Language: C++ - Date: $Date: 2007/09/20 12:48:21 $ - Version: $Revision: 1.12 $ + Date: $Date: 2007/09/21 13:34:09 $ + Version: $Revision: 1.13 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,7 +20,7 @@ // - with a macro : this is the quicker (any doubt ?) // - with a function, passing the params by pointer // - with a function, passing the params by reference (exactly same time) -// - with an inline function described in the main() +// - with an inline function described in the .cxx // absolutely NO effect ?!? // - with a function, described in the .h // absolutely NO effect ?!? @@ -31,7 +31,20 @@ #include "gdcmUtil.h" +#ifdef _MSC_VER +#include +#define GET_TIME(a) a=clock() +#define HOW_LONG(b,a) \ + std::cout << (double) (b-a) << std::endl +#else #include +#define GET_TIME(a) times(&a) +#define HOW_LONG(b,a) \ + std::cout \ + << (long) ((b.tms_utime) - (a.tms_utime)) \ + << std::endl +#endif + #include void frswap (double &a, double &b); @@ -63,13 +76,14 @@ mswap(a, b) \ b = tmp; \ } +// ============= no inline + void frswap(double &a, double &b) { double tmp; tmp = a; a = b; b = tmp; - } void fpswap(double *a, double *b) @@ -78,9 +92,10 @@ void fpswap(double *a, double *b) tmp = *a; *a = *b; *b = tmp; - } +// ============= inline + inline void ifpswap(double *a, double *b) { double tmp; @@ -166,17 +181,35 @@ double passDirectDouble(double a, double b) int TestInline(int argc, char *argv[]) { + +#ifdef _MSC_VER + clock_t tms1, tms2; +#else + struct tms tms1, tms2; +#endif + +// ==================================================================== + std::cout << std::endl << std::endl - << "Just to be sure : sizes of native types" + << "Just to be sure : sizes of native types" << std::endl + << "=======================================" << std::endl << std::endl; // just to know, on every proc + std::cout << "Size of char " << sizeof(char) << std::endl; 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; + 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 << std::endl; + std::cout << "Size of char* " << sizeof(char*) << std::endl; + std::cout << "Size of short int*" << sizeof(short int*)<< std::endl; + std::cout << "Size of int* " << sizeof(int*) << std::endl; + std::cout << "Size of double* " << sizeof(double*) << std::endl; + std::cout << "-----------------" << std::endl; + + // ==================================================================== + unsigned int nbLoop; unsigned int i; @@ -185,448 +218,360 @@ int TestInline(int argc, char *argv[]) else nbLoop = 100000000; - //clock_t r1, r2; - struct tms tms1, tms2; - - double a = 1, b = 2; - - std::cout << "Exchange 2 scalars " << nbLoop << " times" - << std::endl << std::endl; 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); - times(&tms1); - for(i = 0 ; i< nbLoop ; i++) - { - mswap (a,b); - } - //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); - times(&tms1); - for(i = 0 ; i< nbLoop ; i++) - { - frswap (a,b); - } - //r2 = times(&tms2); - times(&tms2); - std::cout - << (long) ((tms2.tms_utime) - (tms1.tms_utime)) - << std::endl; - - // ---------------------------------------- - - std::cout << "Use pointer function" << std::endl; - //r1 = times(&tms1); - times(&tms1); - for(i = 0 ; i< nbLoop ; i++) - { - fpswap (&a, &b); - } - //r2 = times(&tms2); - times(&tms2); - std::cout - << (long) ((tms2.tms_utime) - (tms1.tms_utime)) - << std::endl; - - // ---------------------------------------- - - std::cout << "Use inline, main-defined reference function" << std::endl; - //r1 = times(&tms1); - times(&tms1); - for(i = 0 ; i< nbLoop ; i++) - { - ifrswap (a, b); - } - //r2 = times(&tms2); - times(&tms2); - std::cout - << (long) ((tms2.tms_utime) - (tms1.tms_utime)) - << std::endl; - - // ---------------------------------------- - - std::cout << "Use inline, main-defined pointer function" << std::endl; - //r1 = times(&tms1); - times(&tms1); - for(i = 0 ; i< nbLoop ; i++) - { - ifpswap (&a, &b); - } - //r2 = times(&tms2); - times(&tms2); - std::cout - << (long) ((tms2.tms_utime) - (tms1.tms_utime)) - << std::endl; - - // ---------------------------------------- - -//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 method" - << std::endl; - //r1 = times(&tms1); - gdcm::Util util; - times(&tms1); - for(i = 0 ; i< nbLoop ; i++) - { - util.hifpswap (&a, &b); - } - //r2 = times(&tms2); - times(&tms2); - std::cout - << (long) ((tms2.tms_utime) - (tms1.tms_utime)) - << std::endl; - + double a = 1, b = 2; - // ---------------------------------------- - - std::cout << "Use inline, .h defined, NO inline keyword pointer method" - << std::endl; - //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)) - <