Ioannis Vranos wrote:
[ ... ]
Here are some benchmarks I did a couple of years ago (the last
updated date is a reference link that I added):
http://www23.brinkster.com/noicys/cppfaq.htm
Although I should have used /O2 with VC++ and not /Ox, the difference
on sorting isn't that much.
First of all, I think it's worth noting that all the "work" being
measured in this benchmark is really being done by the standard
library, so the result probably depends at least as much on the
standard library as the compiler per se (e.g. the same compiler with
STLPort would probably produce at least slightly different results).
Second, I'd note that this really only tests sorting, which is common
enough to be worth testing, but provides little indication about how
the compiler will do for lots of other things.
[ ... ]
That said, GCC is good in standards conformance and efficiency.
Keep saying that -- you'll start to believe it eventually. Who knows --
by then it might even be true!
Seriously though, "good" is open to
definition. From a practical viewpoint, its conformance is good enough
to compile most conforming code that most people write. OTOH, I don't
think it has a lot better conformance than most other compilers today.
Likewise for efficiency: compiling well-written code with gcc won't
(usually) render it unusuable, or anything like that. Nonetheless, if
you compile it with something else, the result will _probably_ be quite
a bit smaller and at least a little faster.
If gcc was substantially less expensive than the alternatives, using it
would often still make sense -- but at least on Windows, that's just
not the case. You can have legal copies of nearly every compiler for
Windows (gcc, MS, Borland, Digital Mars and Comeau) for a total
investment well under $100US ($50US if you don't count hard drive space
and download costs).
[ ... test results elided ]
I do not see much difference in this among them.
That's not surprising. For its original intent, the test makes sense,
but it really doesn't stress the compiler enough for a better compiler
to distinguish itself. It's a bit like saying an overweight, 50
year-old smoker and an olympic pentathlete to be in nearly the same
condition because they can both walk 50 feet (slowly) without getting
very out of breath.
Re-running your tests, I also get somewhat different results:
c:\c\source>g++ -msse2 -march=pentium4 -O3 bench1.cpp
c:\c\source>a
vector<int>/sort() sorting time: 2531 translated in seconds: 2.531
valarray<int>/sort() sorting time: 2407 translated in seconds: 2.407
int */qsort() sorting time: 5625 translated in seconds: 5.625
int */sort() sorting time: 2406 translated in seconds: 2.406
c:\c\source>cl -O2b2 -G7y -arch:SSE2 bench1.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
bench1.cpp
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
/out:bench1.exe
bench1.obj
c:\c\source>bench1
vector<int>/sort() sorting time: 2375 translated in seconds: 2.375
valarray<int>/sort() sorting time: 2297 translated in seconds: 2.297
int */qsort() sorting time: 5063 translated in seconds: 5.063
int */sort() sorting time: 2297 translated in seconds: 2.297
Looking at executable sizes, here's what I get (standard library
statically linked in both cases):
MinGW: 480,213
VC++ 7.1: 98,304
Another point: you never seem to tell the compiler what processor to
optimize for, where I've been doing so consistently. Based on the
differences in our results, I'd tentatively guess that MS puts more
effort into processor-specific optimizations, where the gcc team works
more on processor-independent ones. In retrospect, both seem like
fairly obvious choices (for their respective markets), but it's
something I'd never really considered before.
I'd note, however, that at least in MS' case, the default made sense
when it was chosen, but probably doesn't anymore -- by default it
optimizes primarily for the original Pentium. At least IMO, MS should
really update this soon.
Oh -- I almost forgot -- I have the CL environment variable set to
"-GX", so even though it doesn't show up on the command line, exception
handling is enabled for VC++ in every case.