Possible Duplicate:
Performance difference between gcc and g++ for C program
I was checking the improvement of performance with using register storage specifier for the loop control variable when I accidentally noticed that program compiled with gcc runs faster than compiled with g++. Can someone explain it to me?
Here is the code:
#include <stdio.h>
const unsigned long scope = 1000000000;
int main()
{
register unsigned long i;
for (i=0; i < scope; i++);
return 0;
}
;
gcc register.c
time ./a.out
real 0m0.466s
user 0m0.468s
sys 0m0.000s
g++ register.c
time ./a.out
real 0m0.923s
user 0m0.920s
sys 0m0.000s
I can reproduce the behaviour (gcc-4.6.2), the relevant parts of the produced assembly are
C:
C++:
so the C compiler produced a better loop test. Don’t ask me why, I have no idea.