User forums > Using Code::Blocks
CB compiler & performance question
thomas:
Since the Mandraman said we should make an exception:
You're making the same mistake as the big "d00d, gets sum real compila like VS, cuz gcc sux" crowd. You compare apples and oranges.
The version of MinGW that is bundled with Code::Blocks is from the GCC 3.4 branch which is over 4 years old (we bundle this version because it is so old, it has been profoundly tested).
The version based on the GCC 4.2 branch not only offers much better optimisation (which, unlike VS does not bail out when getting anywhere near an intrinsic or assembly), but also allows to link to the standard libary dynamically if desired, producing smaller executables (although I'd rather have bigger executables and no DLLs).
That said, choosing the right options (and coding correctly) can have a great impact on a compiler's performance too.
The code you posted is one of those well-known terribly stupid anti-optimization examples of bad compiler use which still roam the internet. Sorry if I'm saying it like this, but it has to be said. This thing is about as much of an optimization as the clever "xor swap without temporary storage" technique (that one is so "clever" that it hurts).
In your specific example, using standard functions, GCC 4.2 will produce code that runs twice as fast as that hack on any reasonably recent CPU (Pentium III or better) if you only let it.
Unless you target CPUs from the mid-1990s, there is no good reason for such a hack.
When used right, a reasonably recent version of GCC can compete with VS in every way. My deepest respect for the guys who wrote some of the best software available, and they don't even make you pay for it.
mandrav:
--- Quote from: MortenMacFly on March 28, 2008, 09:29:28 am ---
--- Quote from: mandrav on March 28, 2008, 08:31:41 am ---He 's not asking for programming help but wants to discuss about GCC in general.
--- End quote ---
Ok - I didn't know we give GCC support, too. ;-)
--- End quote ---
--- Quote from: thomas on March 28, 2008, 10:22:37 am ---Since the Mandraman said we should make an exception:
--- End quote ---
Well, this is one of those common light-hearted mis-conceptions about GCC. A discussion about this is not off-topic IMHO. If not for anything else, to produce a result for relevant search queries ;).
JGM:
--- Quote from: Fred on March 28, 2008, 05:43:01 am ---
--- Code: ---// ~270 KB
#include <iostream>
int main()
{
printf("This is a test\n");
return 0;
}
--- End code ---
--- Code: ---// ~6 kb
int main()
{
return 0;
}
--- End code ---
--- Code: ---#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <Mmsystem.h>
inline float InvSqrt (float x)
{
float xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i>>1);
x = *(float*)&i;
x = x*(1.5f - xhalf*x*x);
return x;
}
int main()
{
FILE *fp = fopen("Out.txt","wb");
if(!fp)
return 0;
UINT StartTime = timeGetTime();
for(UINT i = 0; i < 10000000; i++)
fprintf(fp,"%f",InvSqrt(50));
UINT EndTime = timeGetTime();
printf("%f\n",((float)(EndTime - StartTime) / 1000));
fclose(fp);
_getch();
return 0;
}
--- End code ---
--- End quote ---
Something that i wanted to point also, is that actually on your code you are not using cout or any class related with include iostream, you are actually using the cstdio included in that file since you are only using printf.
So you should drop:
#include <iostream>
and replace it with
#include <cstdio>
that will give you a smaller executable on gcc, about 5k if i'm correct
Fred:
Thanks for the advices, i did not mean to make this post , not CB related, in fact i thought my problem was perhaps related with the
setup between CB and the compiler, some hidden flags for example.
Also i did not mean to judge MingW vs Microsoft's compiler.. The main reason for why i am moving away from VS in the first place is
the strict licensing from MS(MFC for example, non cross platform etc), and that over the years i have seen the pro's and cons of many different compilers and i know
MS's compilers are far from the top 3 which made me wonder if CB supplied some "behind the scenes" setting to the mingw compiler in my practical
examples, as i expected more juice out of it.
The main reason for why i took iostream in this example was because i always end up using it for starters :) , and my tests ranged from mathematical
operations to IO operations.
JGM
The code above was from me, except InvSqrt(); taken from Quake3 SDK for high performance mathematical test purpose.
Regards,
Fred
JGM:
--- Quote from: Fred on March 29, 2008, 09:55:35 am ---JGM
The code above was from me, except InvSqrt(); taken from Quake3 SDK for high performance mathematical test purpose.
--- End quote ---
Ok, just wanted to point that best regards! :D
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version