Program: gdcm
Module: $RCSfile: TestInline.cxx,v $
Language: C++
- Date: $Date: 2007/09/25 10:07:42 $
- Version: $Revision: 1.14 $
+ Date: $Date: 2008/09/19 09:33:17 $
+ Version: $Revision: 1.21 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// Which CXX_FLAGS, LINKER_FLAGS, ..., must we set to see the difference?
#include "gdcmUtil.h"
-
-#ifdef _MSC_VER
+#include <string.h> // Needed under Suse?!?
+#include <stdlib.h> // atoi
+#if defined(__BORLANDC__) || defined (_MSC_VER)
#include <time.h>
+ #if defined(__BORLANDC__)
+ #include <stdio.h>
+ #endif
#define GET_TIME(a) a=clock()
#define HOW_LONG(b,a) \
- std::cout << (double) (b-a) << std::endl
+ std::cout << (double) (b-a) << std::endl
+
#else
#include <sys/times.h>
#define GET_TIME(a) times(&a)
int TestInline(int argc, char *argv[])
{
-#ifdef _MSC_VER
+#if defined(__BORLANDC__) || defined (_MSC_VER)
clock_t tms1, tms2;
#else
struct tms tms1, tms2;
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 bool " << sizeof(bool) << 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 << "Use inline, .h defined, WITH inline keyword, param passed by pointer"
<< std::endl;
- gdcm::Util util;
+ GDCM_NAME_SPACE::Util util;
GET_TIME(tms1);
for(i = 0 ; i< nbLoop ; i++)
GET_TIME(tms1);
for(i = 0 ; i< nbLoop ; i++)
{
- gdcm::Util::sthifpswap (&a, &b);
+ GDCM_NAME_SPACE::Util::sthifpswap (&a, &b);
}
GET_TIME(tms2);
HOW_LONG(tms2,tms1);
GET_TIME(tms1);
for(i = 0 ; i< nbLoop ; i++)
{
- gdcm::Util::sthNoifpswap (&a, &b);
+ GDCM_NAME_SPACE::Util::sthNoifpswap (&a, &b);
}
GET_TIME(tms2);
HOW_LONG(tms2,tms1);
+
+ // ----------------------------------------
+
+ // Just to point out that playing with pointers doesn't save so much time ...
+
+ std::cout << "Play with arrays\n================" << std::endl;
+
+ nbLoop=1000;
+
+ std::cout << "Copy 2 arrays [i][j]"
+ << std::endl;
+
+
+ unsigned short int z1[128][3118], z2[128][3118];
+ GET_TIME(tms1);
+ for(i = 0 ; i< nbLoop ; i++)
+ {
+ unsigned short int *pv1=&z1[0][0], *pv2=&z2[0][0];
+ for (int j=0;j<3118;j++)
+ for(int i=0; i<128;i++)
+ z2[i][j] = z1[i][j];
+ }
+ GET_TIME(tms2);
+ HOW_LONG(tms2,tms1);
- return 1; // will generate an error,
+ std::cout << "Copy 2 arrays ([i][j], pointer)"
+ << std::endl;
+
+ GET_TIME(tms1);
+ for(i = 0 ; i< nbLoop ; i++)
+ {
+ unsigned short int *pv1=&z1[0][0], *pv2=&z2[0][0];
+ for (int j=0;j<3118;j++)
+ for(int i=0; i<128;i++)
+ z2[i][j] = *pv1++;
+ }
+ GET_TIME(tms2);
+ HOW_LONG(tms2,tms1);
+
+ std::cout << "Copy 2 arrays (2 pointers)" << std::endl;
+ GET_TIME(tms1);
+ // unsigned short int w1[3118*128], w2[3118][128];
+ for(i = 0 ; i< nbLoop ; i++)
+ {
+ unsigned short int *pw1=&z1[0][0], *pw2=&z2[0][0];
+ for (int j=0;j<3118;j++)
+ for(int i=0; i<128;i++)
+ *pw2++ = *pw1++;
+ }
+ GET_TIME(tms2);
+ HOW_LONG(tms2,tms1);
+
+
+ std::cout << "Copy 2 arrays (memcpy)" << std::endl;
+ GET_TIME(tms1);
+ for(i = 0 ; i< nbLoop ; i++)
+ {
+ unsigned short int *pw1=&z1[0][0], *pw2=&z2[0][0];
+ memcpy(pw2,pw1,3118*128*sizeof(unsigned short int));
+ }
+ GET_TIME(tms2);
+ HOW_LONG(tms2,tms1);
+
+
+
+ std::cout << "Transpose 2 arrays [i][j]"
+ << std::endl;
+
+ unsigned short int t1[3118][128], t2[128][3118];
+ GET_TIME(tms1);
+ for(i = 0 ; i< nbLoop ; i++)
+ {
+ unsigned short int *pv1=&t1[0][0], *pv2=&t2[0][0];
+ for (int j=0;j<3118;j++)
+ for(int i=0; i<128;i++)
+ t2[i][j] = t1[j][i];
+ }
+ GET_TIME(tms2);
+ HOW_LONG(tms2,tms1);
+
+
+ std::cout << "Transpose 2 arrays ([i][j], pointer)"
+ << std::endl;
+
+ unsigned short int w1[3118*128], w2[3118][128];
+ GET_TIME(tms1);
+ for(i = 0 ; i< nbLoop ; i++)
+ {
+ unsigned short int *pw1=w1, *pw2=&w2[0][0];
+ for (int j=0;j<3118;j++)
+ for(int i=0; i<128;i++)
+ w2[i][j] = *pw1++;
+ }
+ GET_TIME(tms2);
+ HOW_LONG(tms2,tms1);
+
+
+ std::cout << "Transpose 2 arrays (2 pointers)"
+ << std::endl;
+
+ unsigned short int v1[3118*128], v2[128*3118];
+ GET_TIME(tms1);
+ for(i = 0 ; i< nbLoop ; i++)
+ {
+ unsigned short int *pv1=v1, *pv2=v2;
+ for (int j=0;j<3118;j++)
+ for(int i=0; i<128;i++)
+ *(pv2+i*128+j) = *pv1++;
+ }
+ GET_TIME(tms2);
+ HOW_LONG(tms2,tms1);
+
+
+
+ //return 1; // will generate an error,
// just to allow us to see the full log in the dashboard
- //return 0;
+ return 0;
}