gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > gcc/g++ speed difference?

#12665 - Mix - Fri Nov 21, 2003 4:55 pm

I made my first very simple "game", written in C, and I was compiling using DKA gcc. It basically just loads different screens (mode 4) depending on the keys that you press.

Then I wanted to try modifying it to use C++ and add sprites. Before I changed any code, I first tried compiling the same C code with g++. The resulting program loaded the screens noticeably faster.

Has anyone else noticed a speed difference between gcc and g++? I wonder if g++ is just more efficient, or maybe it's just more efficient with my particular set of code. I'm not sophisticated enough yet to be looking at the ASM output to see what the differences are.

#12675 - Sweex - Sat Nov 22, 2003 12:29 am

There's a lot written about this very subject. I'm sure the Search option on these forums will return some interesting threads for you (and will keep this forum nice and clean!:-)

(In short; it all depends what kind of ++ code you write. It unlikely that g++ will make much faster code than gcc if the source is full ansi-c)
_________________
If everything fails, read the manual: If even that fails, post on forum!

#12756 - Mix - Tue Nov 25, 2003 6:17 pm

Yeah, I don't like to ask questions if they've already been asked. I tried searching, but I guess I just don't know what to search for. Searching on g++ brings back anything with g, such as "e.g.", and searching on gcc brings back all kinds of stuff, such as copies of makefiles. I found a few things about specific pieces of code, but nothing about general speed differences.

Quote:
it all depends what kind of ++ code you write. It unlikely that g++ will make much faster code than gcc if the source is full ansi-c


I didn't have any ++ code. It compiled in gcc, then without touching it I compiled it with g++, and it automatically ran faster.

My guess is that the default optimization options are set differently between gcc and g++, and if you set it correctly for your specific program, you'll end up with about the same performance.

Anyway, it might be a good quick tip for those that are having performance issues and don't want to mess with assembly or compiler options: just give g++ a try and see if it helps.