Sender: jgbauman AT rommel DOT stw DOT uni-erlangen DOT de Message-ID: <378F37A6.E18DC7E0@stud.informatik.uni-erlangen.de> Date: Fri, 16 Jul 1999 15:46:14 +0200 From: Joerg Baumann X-Mailer: Mozilla 4.04 [en] (X11; I; Linux 2.2.9 i686) MIME-Version: 1.0 To: pgcc AT delorie DOT com Subject: not really a bug, but performance problem Content-Type: multipart/mixed; boundary="------------DF8856AA3EBE5425158BD648" Reply-To: pgcc AT delorie DOT com This is a multi-part message in MIME format. --------------DF8856AA3EBE5425158BD648 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, Normally you expect C++ to be slower than C. But for small test-programs you think you can estimate where there will be a preformance penalty using C++ or not. In an undergraduate course (pattern matching) at my univeristy i heared of an example which runs fast as C-Programm, but written as C++-Programm it's much slower. If you look at c_.c and c_.C you can see that they are very similar and you would think, that they should execute at the same speed, but many c++ compilers don't get it right. I tried SUN Workshop compilers 4.2 on an UltraSparc 10 => same speed gcc and g++ 2.7.2.3 " => same speed pgcc-2.91.66 on linux pentium II 333 => c 1.5 times faster than c++ But the most astonishing thing was. c_.c compiled with gcc-2.7.2.1 was 1.15 times faster than c_.c compiled with pgcc-2.91.66 the generated assemblerfiles and timing-results are in t13.s and t10.s i hope you'll find this interesting, and please excuse my bad english joerg -------------------------------------------------------------------- cpu time/usefulness ratio too high -- core dumped. Joerg Baumann (joerg DOT baumann AT stud DOT informatik DOT uni-erlangen DOT de) --------------DF8856AA3EBE5425158BD648 Content-Type: text/plain; charset=us-ascii; name="c_.C" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="c_.C" #include #include #include const int MAX=512; class H{ int size; int * const h; public: H():h(new int[256]){ assert(h!=NULL); } inline int& operator[](int i) const { return h[i]; } }; int main(int argc,char * argv[]){ int i,j,k,m; unsigned char pic[MAX][MAX]; H h; if (argc!=2) { cout << "usage: c_ loop\n"< #include #define MAX 512 typedef struct _H { int s; int *h; }H; int main(int argc,char * argv[]){ int i,j,k,m; unsigned char pic[MAX][MAX]; H h; h.h=(int*)malloc(sizeof(int)*4); assert(h.h!=NULL); if (argc!=2) { printf("usage: c_ loop\n"); exit(-1); } m=atoi(argv[1]); for (k=0;k