Jump to content

  • Log In with Google      Sign In   
  • Create Account

gcc vs. VC++ code optimization


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
52 replies to this topic

#1 cignox1   Members   -  Reputation: 723

Like
0Likes
Like

Posted 01 June 2010 - 10:20 PM

I'm thinking to move my raytracer from a VS solution to an Eclipse project, but as compiler optimizations skills are fundamental in such kind of applications, I would like to know how do they compare in the most recent version (for gcc the windows port). I was not able to find reliable and recent benchmarks, someone has any knowledge to share?

Please, no flames!

Note: I know that some IDEs (perhaps Eclipse too) can make use of the VC++ compiler, but I really like VS so I will move only if by doing so I can leave the proprietary software (main reason to do that).
Thank you!

Sponsor:

#2 Sneftel   Senior Moderators   -  Reputation: 1781

Like
0Likes
Like

Posted 01 June 2010 - 10:26 PM

There's just no way to compare in a way that is both general and accurate. The general understanding is that VC++ produces somewhat more optimized code, but I've had code that VC++ did a really idiotic job on compared to GCC. Luckily, moving code between VC++ and MingW is painless... there's usually some latent header problems that show up, maybe you need to redo some dynamic linking stuff, but nothing requiring large-scale refactoring. (Expect to spend a lot more time if you insist upon a quiet -Wall.)

#3 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 01 June 2010 - 10:37 PM

My experience is that gcc is

0) more up-to-date (way shorter release cycles)
1) optimizes better
2) comes with a more optimized stdlibc++ (e.g. MSVC's implementation of valarray does, in contrary to gcc's provision, not use expression templates)

As for 1), some months ago I coded some expression templates to be used for spectral computations in picogen. I tried out some benchmark in both gcc and msvc. The MSVC version was only roughly only at 50% of gcc's performance, with standard optimization flags (read: -O3 and the MSVC alternative).

If you must rely on assembly for some reason, than gcc will integrate it with the rest of your code and apply optimizations, as compared to MSVC, where inline assembly does not work on x64 and where it puts some serious contraints on surrounding code and surrounding function.

gcc is also pretty good at auto-vectorization and SSE code generation. I'll try to do some re-creatable benchmarking later, and come back to thread :)



edit:

On the other hand, here are some not serious to bones benchmarks:

http://keyj.s2000.ws/?p=86 -> basically MSVC==gcc, but it's from soon 2009, and there have been major improvements like the merge of the graphite branch into gcc 4.4 and addition of whopr / link-time optimizations in gcc 4.5. So if it is the case that MSVC dit not improve very, very much since the last version, the winner is divinable (from real world: picogen with gcc 4.4 is roughly 1.4 times faster than with gcc 4.3).

Btw, gcc's support for C++0x is more mature: gcc / msvc.


And, it is often a mistake by ppl to assume that gcc is developed by "freetards" (not that it would mean anything, but), but this and that (only one of many examples) tell another story.

[Edited by - phresnel on June 2, 2010 4:37:07 AM]

#4 cignox1   Members   -  Reputation: 723

Like
0Likes
Like

Posted 02 June 2010 - 03:05 AM

Thank you both.

@phresnel: your experience is expecially valuable for me as you are working on somewhat similar algorithms. If, as I suppose, you are talking about gcc under windows, then I should seriouly consider moving my code to gcc.

Thank you!

#5 Promit   Moderators   -  Reputation: 7191

Like
0Likes
Like

Posted 02 June 2010 - 04:06 AM

When I was working on a PS3/Xbox game, the Xbox's VC based compiler generated significantly better code than the PS3's GCC port. There were a number of major optimizations (entire categories) missing from GCC, including whole-program. It also tended to generate longer code that ruined its own inlining logic. I don't know to what extent that applies to the PC platform -- but IMO using GCC on Windows is a bad idea anyway. You should be using the preferred tools and compiler chain for any given platform unless there's a really compelling reason not to. At least that's how I see things.

#6 Ameise   Members   -  Reputation: 733

Like
0Likes
Like

Posted 02 June 2010 - 04:10 AM

From my understanding, GCC used to have issues with compiling templated classes -- I don't know if that's true or if it's been fixed since if it were ever a problem, but thought I'd throw in my halfpence.

If you're working with Windows, though, use VC++. It's the preferred compiler for the platform, and should generate the best code for it 99% of the time.

#7 Steve132   Members   -  Reputation: 433

Like
0Likes
Like

Posted 02 June 2010 - 04:21 AM

Quote:
Original post by Promit
When I was working on a PS3/Xbox game, the Xbox's VC based compiler generated significantly better code than the PS3's GCC port. There were a number of major optimizations (entire categories) missing from GCC, including whole-program. It also tended to generate longer code that ruined its own inlining logic. I don't know to what extent that applies to the PC platform -- but IMO using GCC on Windows is a bad idea anyway. You should be using the preferred tools and compiler chain for any given platform unless there's a really compelling reason not to. At least that's how I see things.


Recently, GCC has undergone some massive improvements... gcc on ps3 was what, 3.2? 3.4? 4.1? All those issues have been fixed in 4.4 or 4.5. From my personal experience, this is not exactly a fair metric, because of OS and processor differences, but recently I compiled a number-crunching program of mine on Win7 with msvc and an i7 processor, and the same program on ubuntu 10.04 with gcc 4.4 and a core 2 duo at half the clock. Amazingly, despite a significant decrease in processor speed and memory, gcc 4.4 CREAMED msvc, with a factor of 3 speedup on the same code. YMMV


#8 outRider   Members   -  Reputation: 852

Like
0Likes
Like

Posted 02 June 2010 - 04:22 AM

Quote:
Original post by Promit
When I was working on a PS3/Xbox game, the Xbox's VC based compiler generated significantly better code than the PS3's GCC port. There were a number of major optimizations (entire categories) missing from GCC, including whole-program. It also tended to generate longer code that ruined its own inlining logic. I don't know to what extent that applies to the PC platform -- but IMO using GCC on Windows is a bad idea anyway. You should be using the preferred tools and compiler chain for any given platform unless there's a really compelling reason not to. At least that's how I see things.


GCC for PPC not that great from my experience, compared to say, IBM's. Even more so on CELL. That's understandable however; I expect x86 GCC gets much more attention than most other platforms.

#9 Promit   Moderators   -  Reputation: 7191

Like
0Likes
Like

Posted 02 June 2010 - 04:28 AM

Quote:
Original post by Steve132
Recently, GCC has undergone some massive improvements... gcc on ps3 was what, 3.2? 3.4? 4.1? All those issues have been fixed in 4.4 or 4.5.
3.4, IIRC, and the SN compiler was becoming the favored tool rather than GCC. I don't deny I might be out of date.
Quote:
From my personal experience, this is not exactly a fair metric, because of OS and processor differences, but recently I compiled a number-crunching program of mine on Win7 with msvc and an i7 processor, and the same program on ubuntu 10.04 with gcc 4.4 and a core 2 duo at half the clock. Amazingly, despite a significant decrease in processor speed and memory, gcc 4.4 CREAMED msvc, with a factor of 3 speedup on the same code. YMMV
I'd be cautious about blaming this difference on compilers, given that you're looking at completely different everything.

#10 Steve132   Members   -  Reputation: 433

Like
0Likes
Like

Posted 02 June 2010 - 04:37 AM

Quote:
Original post by Promit
Quote:
Original post by Steve132
Recently, GCC has undergone some massive improvements... gcc on ps3 was what, 3.2? 3.4? 4.1? All those issues have been fixed in 4.4 or 4.5.
3.4, IIRC, and the SN compiler was becoming the favored tool rather than GCC. I don't deny I might be out of date.
Quote:
From my personal experience, this is not exactly a fair metric, because of OS and processor differences, but recently I compiled a number-crunching program of mine on Win7 with msvc and an i7 processor, and the same program on ubuntu 10.04 with gcc 4.4 and a core 2 duo at half the clock. Amazingly, despite a significant decrease in processor speed and memory, gcc 4.4 CREAMED msvc, with a factor of 3 speedup on the same code. YMMV
I'd be cautious about blaming this difference on compilers, given that you're looking at completely different everything.


Yeah, you are totally right, like I said, its not a fair metric, and I'd love to do real and fair benchmarks. The only reason it struck me was the fact that between the two machines, the gcc one had everything conventional wisdom says is an extreme disadvantage. The processor was 3 years older, the system had a quarter of the memory, and the FSB was half as fast, and it STILL outperformed it.



#11 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 02 June 2010 - 04:46 AM

Quote:
Promit
but IMO using GCC on Windows is a bad idea anyway

Why? I don't see any issues. Maybe when your preferred IDE is MSVC, dunno, I lack the experience of piping gcc into MSVC. But apart from that?

From the multi-platform developer's point of view, there's a reason to use gcc and the whole toolchain (read: a good MinGw installation) on windows: Identical toolchains = Mostly identical code (including Makefiles). Why waste time porting to MSVC, when you anyways don't use that IDE.

[From the scientific point of view: GNU has expression-template-valarray.]


Quote:
Ameise
From my understanding, GCC used to have issues with compiling templated classes

I think you are mixing something up ...

Quote:
Q: Ima porting code to gcc, but gcc is buggy
Quote:
A: Add a typename there


Quote:
I don't know if that's true or if it's been fixed since if it were ever a problem, but thought I'd throw in my halfpence.

I can assure that any gcc 4.x will compile metatrace (gah, gitorious has problems, here).

And 4.x is around for years now. Can't tell about 3.x series, but anything older than 4.3.5 is unmaintained and hence arguing about it is as arguing about MSVC 2005.

Quote:
and should generate the best code for it 99% of the time.

What gives you the impression?

#12 Ameise   Members   -  Reputation: 733

Like
0Likes
Like

Posted 02 June 2010 - 04:51 AM

It was something I'd read long ago. Like I said, I wasn't sure if it was true or still accurate - I don't normally use GCC.

I would -love- to see a true comparison between VC++ and GCC on a Windows system with equivalent projects - a true benchmark.

BTW, I wish I lived in a city called 'Pretty Valley'... darf ich bei dir leben? :D

#13 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 02 June 2010 - 04:56 AM

Quote:
Original post by Ameise
It was something I'd read long ago. Like I said, I wasn't sure if it was true or still accurate - I don't normally use GCC.

Don't forget to not believe everything straight by reading, and long ago means decades to centuries in IT measure ;)

Quote:
I would -love- to see a true comparison between VC++ and GCC on a Windows system with equivalent projects - a true benchmark.

Tbh, I am just about to download a copy of the newest MSVC to see whether I can stuff picogen into it.

edit: Eeeks, SP3 required ... can only be days .|
edit2: Two [virtual] reboots and two [physical] hours later, the update is complete [edit2+1: actually three reboots, as for an update of VirtualBox additions]
edit3: The fuck why must I reboot to install MSVC? [edit3+1: and indeed the reboot was to install the stuff, not to be able to use it]
edit4: The fuck is this? Two reboots to install a piece of software??
edit5: Wait what, no reboot after install? The fuck is this?
edit6: I could live with the old GUI. But this is one is ugly.
edit7: Why can I drag+drop src-files recursively, but not header-files? (oh, and forgive my ranting, just the usual I am not used to it stuff)
edit8: [sorry, I know this isn't twitter] Seriously, importing code into code::blocks ide worked in roughly 5% of the time I needed now, but maybe I just missed the correct trick (now that I mention code::blocks, why did I not just use that, me idiot)
edit9: has anybody recognized that after two years there's a new stable release of code::blocks as of May 30?; edit9+1: installation complete within 5 minutes including download. but has no support for MSVC10 yet.
edit10: uhm, I wonder if there is now hierarchical view of the file-tree. having 80 headerfiles and some 50-70 (didn't count) flat is not that nice ...

Quote:
BTW, I wish I lived in a city called 'Pretty Valley'... darf ich bei dir leben? :D

More like 'Nice Valley', but that doesn't really fit, as 'nice' is the feminine form, and the name of a small river, otherwise it would be 'Nettes Tal', heh :D

[Edited by - phresnel on June 2, 2010 2:56:09 PM]

#14 Ameise   Members   -  Reputation: 733

Like
0Likes
Like

Posted 02 June 2010 - 05:03 AM

Quote:
Original post by phresnel
More like 'Nice Valley', but that doesn't really fit, as 'nice' is the feminine form, and the name of a small river, otherwise it would be 'Nettes Tal', heh :D


Eh, most of the German city names are broken down versions of old names, and don't often follow the same proper conventions anymore... like München, which was originally 'Mönchen', due to it being founded by monks. But completely unrelated to programming, unlike Pascalberg and Perlau.

Let me know how the benchmark goes, though.

#15 iMalc   Crossbones+   -  Reputation: 2306

Like
0Likes
Like

Posted 02 June 2010 - 08:05 AM

If you're the kind of person who profiles as they optimise then you'll probably find that switching to another compiler gives a slower result (as I did).
It seems that to some degree my code becomes optimised towards the compiler I'm using at the time.

#16 Washu   Senior Moderators   -  Reputation: 5194

Like
0Likes
Like

Posted 02 June 2010 - 08:09 AM

Quote:
Original post by phresnel
edit: Eeeks, SP3 required ... can only be days .|
edit2: Two [virtual] reboots and two [physical] hours later, the update is complete [edit2+1: actually three reboots, as for an update of VirtualBox additions]
edit3: The fuck why must I reboot to install MSVC? [edit3+1: and indeed the reboot was to install the stuff, not to be able to use it]
edit4: The fuck is this? Two reboots to install a piece of software??

I didn't have to reboot once. Then again I'm on Windows 7. The reason it needs restarts though is generally because certain system files that the prereqs are modifying are in use. A prime example is the .net runtime prereq, which requires certain system modifications to hook it all in.

As far as GCC vs MSVC... frankly, who cares?

If you really need your compiler to generate the best performing code for your PC platform... ICC with the AMD patch is probably about as good as it gets. Requires heavy debugging and testing though to ensure correctness.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX


#17 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 02 June 2010 - 08:42 AM

Quote:
Original post by Washu
Quote:
Original post by phresnel
edit: Eeeks, SP3 required ... can only be days .|
edit2: Two [virtual] reboots and two [physical] hours later, the update is complete [edit2+1: actually three reboots, as for an update of VirtualBox additions]
edit3: The fuck why must I reboot to install MSVC? [edit3+1: and indeed the reboot was to install the stuff, not to be able to use it]
edit4: The fuck is this? Two reboots to install a piece of software??

I didn't have to reboot once. Then again I'm on Windows 7. The reason it needs restarts though is generally because certain system files that the prereqs are modifying are in use. A prime example is the .net runtime prereq, which requires certain system modifications to hook it all in.

Admittedly, I run XP.

Quote:
As far as GCC vs MSVC... frankly, who cares?

The OP: "gcc vs. VC++ code optimization", and for those who write number crunchers, this can indeed be very relevant :)

#18 cignox1   Members   -  Reputation: 723

Like
0Likes
Like

Posted 02 June 2010 - 08:49 AM

Quote:
Original post by Washu
As far as GCC vs MSVC... frankly, who cares?

If you really need your compiler to generate the best performing code for your PC platform... ICC with the AMD patch is probably about as good as it gets. Requires heavy debugging and testing though to ensure correctness.


You are right but IIRC IIC is not open source nor free, and the main reason to switch was exactly that. Its just that I don't feel like migrating the code just to discover a 30% speed loss.
In short, given comparable IDE tools (debugger + profiler) and comparable compiler quality, I would like to move to OS software though I highly doubt that I will find a debugger close to the VS one).

#19 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 02 June 2010 - 08:57 AM

edit11 (but I think worth enough for a seperate reply):

Another two three (?) two reasons to not use MSVC are:

0) that it still has no support for OpenMP 3.0, and for some reason fails to find omp.h, even though I've enabled OpenMP in the settings.

1) doesn't support 64bit enum valus (at least on i386) (testcase: http://gitorious.org/picogen/picogen/blobs/master/src/kallisto/traits/int_traits.hh)

edit:

2) why does MSVC make auto-generated operator= private? or what am I doing wrong? (i.e., in line 215 of http://gitorious.org/picogen/picogen/blobs/master/src/kallisto/rng/kiss.hh, I get invalid access to CONG::operator=) No, this one was a misplaced using statement, sorry

[Edited by - phresnel on June 2, 2010 4:57:39 PM]

#20 Yann L   Moderators   -  Reputation: 1798

Like
0Likes
Like

Posted 02 June 2010 - 08:59 AM

Quote:
Original post by phresnel
Quote:
Promit
but IMO using GCC on Windows is a bad idea anyway

Why? I don't see any issues.

You have to use GDB for debugging. And that thing is absolute garbage.

Anyway, GCC itself is pretty good. From my experience on very computationally heavy GI algorithms, both gcc and msvc are about the same on average. Sometimes one or the other is ahead, but it really depends on the code and the used optimization options. There is no generally valid trend, as far as I could tell.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS