views:

462

answers:

1

A few days ago I was told that recent versions of g++ produce "better" x86 code than MSVC 2008. Basically GCC with full optimization produces faster applications than MSVC with full optimizations.

While it's certainly correct to state that this, if true, depends a great deal on the application and the C++ code used (and I'm in the process of evaluating this claim for my application), I'm wondering what do others think.

In essence, what have been your personal experiences when comparing the output of these two compilers?

I'm asking about MinGW, but if your experience with vanilla GCC is somehow valid here, feel free to share that too.

+2  A: 

My experience is compiling my C++ JPEG-LS image compression project. http://charls.codeplex.com

For me, Visual C++ was significantly faster.

I compiled it mostly with G++ on linux. After a lot of tuning, the G++ version was still about 10-15% slower on the same hardware (the same physical machine, dual booted as linux). That was after many hours of searching for G++ optimization options that actually helped. Just compiling with default optimizations G++ was 60% slower than Visual C++.

My project is perhaps somewhat a-typical because it is not C, but C++ and requires the compiler to do a lot of inlining. On both compilers, I enforce inlining to happen.

Also, it was offered to me as an explanation that the x86 has very few registers, and G++ was not good at allocating them.

jdv
which G++ version did you use ?
smerlin
By "default optimizations", do you mean "-O3"? Or just "default", meaning no optimizations?
Lucas
With "default optimization", i mean -O3. I compiled with GCC 4.2.3. I also had to force G++ to optimize for modern CPU's by hand. I also went back to the latest figures, in the end, the difference was 10-15%, not 20%. Please don't get angry.
jdv
LOL, who's angry? :) You've given me a valid data point, and for that I thank you.
Lucas
Since no one else felt inclined to post an answer and yours is helpful and informative, I'm marking it as accepted. Thanks again!
Lucas