Related articles |
---|
Will C++ compilers ever be better than C compilers? mayan@watson.ibm.com (1998-08-02) |
Re: Will C++ compilers ever be better than C compilers? qjackson@wave.home.com (Quinn Tyler Jackson) (1998-08-03) |
Re: Will C++ compilers ever be better than C compilers? bill@amber.ssd.csd.harris.com (1998-08-03) |
Re: Will C++ compilers ever be better than C compilers? michael.ball@Eng.Sun.COM (Michael Ball) (1998-08-03) |
Re: Will C++ compilers ever be better than C compilers? danielv@crt.umontreal.ca (Daniel Villeneuve) (1998-08-03) |
Re: Will C++ compilers ever be better than C compilers? jeff@jeff-jackson.com (Jeff Jackson) (1998-08-03) |
Re: Will C++ compilers ever be better than C compilers? bob.morgan@digital.com (1998-08-03) |
Re: Will C++ compilers ever be better than C compilers? chase@naturalbridge.com (David Chase) (1998-08-03) |
[7 later articles] |
From: | "Quinn Tyler Jackson" <qjackson@wave.home.com> |
Newsgroups: | comp.compilers |
Date: | 3 Aug 1998 17:53:34 -0400 |
Organization: | Compilers Central |
References: | 98-08-011 |
Keywords: | C, C++, optimize, performance |
>To summarize:
> C++ compilers will produce code with lower performance than
> C compilers on equivalent code, because of the extra features of
> C++. This will occur because:
> 1) less resources will be available for performance optimizations
> 2) more resources are needed to implement and test the same
> optimization in C++ compared to C.
> 3) much of the available optimization resources will be allocated to
> optimizations irrelevant to "C subset" code.
>Do you agree?
Not entirely. Especially with point 3.
>Can you provide concrete examples?
A few days back, while writing a blurb on the equivalence of
algorithms, I made the assumption that the VC++ 5.0 compiler wouldn't
be able to optimize the following code:
int multiply_the_slow_way(int a, int b)
{
int c = 0;
for(int i = 0; i < b; c += a, i++);
return c;
}
int main(void)
{
int a = 0;
int b = 0;
cin >> a;
cin >> b;
cout << multiply_the_slow_way(a,b) << end;
}
With optimizations on, the compiler generated the appropriate code --
it did an integer multiplication directly (I verified this by looking
at the generated assembler code). When I did this:
cout << multiply_the_slow_way(10,2) << end;
it generated the constant 20 directly.
C++ compiler, mixed C/C++ code -- optimization recognized that my
function was multiplication and behaved accordingly.
Your mileage may vary.
--
Quinn Tyler Jackson
email: qjackson@wave.home.com
url: http://www.qtj.net/~quinn/
ftp: qtj.net
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.