473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

c compilation - gcc vs visual c

hello:

I recently compiled a numerically intensive c project under cygwin gcc
3.4.4 and microsoft visual c. The platform is intel T2400 1.83 ghz
dual core lap top.

the numerical stuff is both floating point and integer intensive

The gcc optimized (-O3) vs non optimized improved the performance 30 %

visual c optimized (standard , check 'release; under visual c 2005)
vs non optimized ('build') was a whopping 8x performance gain

but the most surprising thing was visual c optimized was 2x
performance over gcc optimized.

is anybody else seeing the same thing. if this is true microsoft c
compiler is in a different league altogether

i was not successful so far compiling under mingw. will it make dent ?
2x is hard to overcome
Jun 27 '08 #1
37 2863
ku******@gmail.com wrote:
hello:

I recently compiled a numerically intensive c project under cygwin gcc
3.4.4 and microsoft visual c. The platform is intel T2400 1.83 ghz
dual core lap top.

the numerical stuff is both floating point and integer intensive

The gcc optimized (-O3) vs non optimized improved the performance 30 %
The more you go with higher optimizations, the slower
it goes. Use -O2.

visual c optimized (standard , check 'release; under visual c 2005)
vs non optimized ('build') was a whopping 8x performance gain
This is because the non optimized version injects a lot of
checking code to avoid bugs. It is slower than strictly necessary.
For instance they check at function exit if there wasn't a stack overwrite.

but the most surprising thing was visual c optimized was 2x
performance over gcc optimized.
Intel compiler is even better than Microsoft. It is the best compiler
for the intel architecture. Period.
is anybody else seeing the same thing. if this is true microsoft c
compiler is in a different league altogether
Obviously Microsoft leaves gcc far behind, and I have been seeing this
since at least 8-9 years.
i was not successful so far compiling under mingw. will it make dent ?
2x is hard to overcome

mingw is just gcc using Microsoft run time library. Do not expect
anything better/worst.

It is not surprising that gcc is slower than Microsoft since the
people behind each project have vastly different objectives and
budgets to implement them.

Gcc is running in many platforms and architectures.
Microsoft is running in one platform exclusively.

Gcc implements standards like C99 (module small problems), Microsoft
implements only Microsoft environments (.net, etc). Microsoft is
still at C89 level.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jun 27 '08 #2
jacob navia wrote:
Microsoft is running in one platform exclusively.
Sorry, but that's untrue. The platforms I know are IA32, Intel's and AMD's
64 bit platforms, MIPS, ARM, SH and maybe some more. Note that the latter
are used for MS' embedded platform.

Uli

Jun 27 '08 #3

kumar...@gmail.com wrote:
hello:

I recently compiled a numerically intensive c project under cygwin gcc
3.4.4 and microsoft visual c. The platform is intel T2400 1.83 ghz
dual core lap top.

the numerical stuff is both floating point and integer intensive

The gcc optimized (-O3) vs non optimized improved the performance 30 %
It's probably not going to help you, but as a point of interest I have
sometimes found -Os
to work better (optimize for size) with gcc.

Stijn
Jun 27 '08 #4
On May 9, 4:20*pm, jacob navia <ja...@nospam.comwrote:
kumar...@gmail.com wrote:
hello:
I recently compiled a numerically intensive c project under cygwin gcc
3.4.4 and microsoft visual c. The platform is intel T2400 1.83 ghz
dual core lap top.
the numerical stuff is both floating point and integer intensive
The gcc optimized (-O3) vs non optimized improved the performance 30 %

The more you go with higher optimizations, the slower
it goes. Use -O2.
visual c optimized (standard , check 'release; under visual c 2005)
vs non optimized ('build') was a whopping 8x performance gain

This is because the non optimized version injects a lot of
checking code to avoid bugs. It is slower than strictly necessary.
For instance they check at function exit if there wasn't a stack overwrite..
but the most surprising thing was visual c optimized was 2x
performance over gcc optimized.

Intel compiler is even better than Microsoft. It is the best compiler
for the intel architecture. Period.
is anybody else seeing the same thing. if this is true microsoft c
compiler is in a different league altogether

Obviously Microsoft leaves gcc far behind, and I have been seeing this
since at least 8-9 years.
i was not successful so far compiling under mingw. will it make dent ?
2x is hard to overcome

mingw is just gcc using Microsoft run time library. Do not expect
anything better/worst.

It is not surprising that gcc is slower than Microsoft since the
people behind each project have vastly different objectives and
budgets to implement them.

Gcc is running in many platforms and architectures.
Microsoft is running in one platform exclusively.

Gcc implements standards like C99 (module small problems), Microsoft
implements only Microsoft *environments (.net, etc). Microsoft is
still at C89 level.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32
the problem is in my type of product i have to recommend windows
platform because based on gcc performance an apple to apple linux
platform will run 2x slower
Jun 27 '08 #5
moi
On Fri, 09 May 2008 14:03:14 -0700, kumarchi wrote:
On May 9, 4:20Â*pm, jacob navia <ja...@nospam.comwrote:
>kumar...@gmail.com wrote:
hello:
I recently compiled a numerically intensive c project under cygwin
gcc 3.4.4 and microsoft visual c. The platform is intel T2400 1.83
ghz dual core lap top.
the numerical stuff is both floating point and integer intensive
The gcc optimized (-O3) vs non optimized improved the performance 30
%

The more you go with higher optimizations, the slower it goes. Use -O2.
visual c optimized (standard , check 'release; under visual c 2005)
vs non optimized ('build') was a whopping 8x performance gain

This is because the non optimized version injects a lot of checking
code to avoid bugs. It is slower than strictly necessary. For instance
they check at function exit if there wasn't a stack overwrite.
but the most surprising thing was visual c optimized was 2x
performance over gcc optimized.
>Obviously Microsoft leaves gcc far behind, and I have been seeing this
since at least 8-9 years.
i was not successful so far compiling under mingw. will it make dent
? 2x is hard to overcome
the problem is in my type of product i have to recommend windows
platform because based on gcc performance an apple to apple linux
platform will run 2x slower
Did you enable the -march=cpu-type -msse[2] code generation option ?

HTH,
AvK
Jun 27 '08 #6
ku******@gmail.com wrote:
>
the problem is in my type of product i have to recommend windows
platform because based on gcc performance an apple to apple linux
platform will run 2x slower
Then try the Intel compiler, which is also cross platform.

--
Ian Collins.
Jun 27 '08 #7
ku******@gmail.com wrote:
>
the problem is in my type of product i have to recommend windows
platform because based on gcc performance an apple to apple linux
platform will run 2x slower
You can use Intel compiler under linux. Your code will be
faster than under windows/MSVC.

Of course do not tell your customers about Intel/Windows.
:-)
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jun 27 '08 #8
Niz
On 2008-05-09 22:03:14 +0100, ku******@gmail.com said:
the problem is in my type of product i have to recommend windows
platform because based on gcc performance an apple to apple linux
platform will run 2x slower
Your using a version of GCC which is 3 years old. Perhaps try with one
of the newer versions with all the relevant optimisations and then see
if the difference is so great. Macs have GCC 4.0.1 (soon to be 4.2.2)
as their base compiler under Leopard.

Although as others have said, the Intel compiler is king of the hill
for producing fast Intel x86 and x86_64 code.

Jun 27 '08 #9
On 9 May 2008 at 21:03, ku******@gmail.com wrote:
the problem is in my type of product i have to recommend windows
platform because based on gcc performance an apple to apple linux
platform will run 2x slower
If speed is that important to you, why don't you hand-optimize the
assembly?

Jun 27 '08 #10

<ku******@gmail.comwrote in message
news:47**********************************@j22g2000 hsf.googlegroups.com...
hello:

I recently compiled a numerically intensive c project under cygwin gcc
3.4.4 and microsoft visual c. The platform is intel T2400 1.83 ghz
dual core lap top.

the numerical stuff is both floating point and integer intensive

The gcc optimized (-O3) vs non optimized improved the performance 30 %

visual c optimized (standard , check 'release; under visual c 2005)
vs non optimized ('build') was a whopping 8x performance gain

but the most surprising thing was visual c optimized was 2x
performance over gcc optimized.
likely reason:
MS focuses a lot more on specific optimizations, and tweaking performance
for specific targets;
gcc, however, targets many targets, and tends to use far more generic code
generation (they try more to leverage fancy general purpose optimizations,
rather than arch-specific tweaks for various special cases).

in any case, gcc tends to, fairly often, produce fairly silly code (even
with optimizations), and, sadly, even with a very braindead lower-compiler
design (a hacked over stack machine), and optimizations focusing more on
"common special cases", it is not too hard to match or somewhat exceed gcc's
performance...

IMO, the 'O' options may well be Obfuscate rather than Optimize...
actually, one of the better ways at optimizing, would be likely to implement
a kind of abstract combinatorial tester, which would basically search the
space of possible optimizations and look for the ones with the lowest
simulated cost. sadly though, this will not work so well in the face of
usage patterns, which require actually using the code (the general option
could treat a very common case like an uncommon case, ...).

in something like a VM, it could be possible to use a kind of genetic
evolver for adapting functions (initially, it compiles functions
generically, and any functions it detects are using a significant portion of
the time, it starts mutating in an attempt to improve the general
performance). later, if/when a "final" version is desired, it uses the
versions of the functions found to be most effective.

note that this would likely be confined to the realms of low-level
optimization, with what are typically the biggest time wasters (general
algorithmic issues), being beyond the scope of such a tool...
the simplest approach, however (and the one I currently use in my compiler),
is to basically just test the compiler, and any obvious issues in the output
(silly code), are ones I focus on fixing.

the compiler machinery itself in my case, as this level, is little more than
just a very large and elaborate mass of decision trees (no fancy transforms
or general optimizer machinery, more just operations dispatched through a
maze of function calls).

this approach seems to work good enough IME...

is anybody else seeing the same thing. if this is true microsoft c
compiler is in a different league altogether
that, or, most of us are not that concerned with raw performance (vs having
a compiler we are not obligated to pay for...).

none the less, MS has at least a decent compiler in these regards...

i was not successful so far compiling under mingw. will it make dent ?
2x is hard to overcome
well, with gcc, it is hard to do much better...

as noted, MSVC and Intel are good options...


Jun 27 '08 #11
On May 9, 6:41*pm, "cr88192" <cr88...@NOSPAM.hotmail.comwrote:
<kumar...@gmail.comwrote in message

news:47**********************************@j22g2000 hsf.googlegroups.com...
hello:
I recently compiled a numerically intensive c project under cygwin gcc
3.4.4 and microsoft visual c. The platform is intel T2400 1.83 ghz
dual core lap top.
the numerical stuff is both floating point and integer intensive
The gcc optimized (-O3) vs non optimized improved the performance 30 %
visual c optimized (standard , check 'release; under visual c 2005)
vs non optimized ('build') was a whopping 8x performance gain
but the most surprising thing was visual c optimized was 2x
performance over gcc optimized.

likely reason:
MS focuses a lot more on specific optimizations, and tweaking performance
for specific targets;
gcc, however, targets many targets, and tends to use far more generic code
generation (they try more to leverage fancy general purpose optimizations,
rather than arch-specific tweaks for various special cases).

in any case, gcc tends to, fairly often, produce fairly silly code (even
with optimizations), and, sadly, even with a very braindead lower-compiler
design (a hacked over stack machine), and optimizations focusing more on
"common special cases", it is not too hard to match or somewhat exceed gcc's
performance...

IMO, the 'O' options may well be Obfuscate rather than Optimize...

actually, one of the better ways at optimizing, would be likely to implement
a kind of abstract combinatorial tester, which would basically search the
space of possible optimizations and look for the ones with the lowest
simulated cost. sadly though, this will not work so well in the face of
usage patterns, which require actually using the code (the general option
could treat a very common case like an uncommon case, ...).

in something like a VM, it could be possible to use a kind of genetic
evolver for adapting functions (initially, it compiles functions
generically, and any functions it detects are using a significant portion of
the time, it starts mutating in an attempt to improve the general
performance). later, if/when a "final" version is desired, it uses the
versions of the functions found to be most effective.

note that this would likely be confined to the realms of low-level
optimization, with what are typically the biggest time wasters (general
algorithmic issues), being beyond the scope of such a tool...

the simplest approach, however (and the one I currently use in my compiler),
is to basically just test the compiler, and any obvious issues in the output
(silly code), are ones I focus on fixing.

the compiler machinery itself in my case, as this level, is little more than
just a very large and elaborate mass of decision trees (no fancy transforms
or general optimizer machinery, more just operations dispatched through a
maze of function calls).

this approach seems to work good enough IME...
is anybody else seeing the same thing. if this is true microsoft c
compiler is in a different league altogether

that, or, most of us are not that concerned with raw performance (vs having
a compiler we are not obligated to pay for...).

none the less, MS has at least a decent compiler in these regards...
i was not successful so far compiling under mingw. will it make dent ?
2x is hard to overcome

well, with gcc, it is hard to do much better...

as noted, MSVC and Intel are good options...
thanx all of you for responding. I was totally unprepared for such a
vast performance difference (2x msvc vs gcc) and my code is not at all
special(no UI, complicated classes etc). it simply does lots of
floating point array(mainly through fft) and normal integer
operations

I used -O3 flag and in my case so far it seems to be better than O2.
msvc by default uses their own O2.

I cannot believe such a blatant difference will go unnoticed for long

in our type of situation the intel compiler is not an option.
primarily because we have a standaradized dll plug in architecture
and so (if windoz do msvc) applies.
Jun 27 '08 #12
On May 9, 6:41*pm, "cr88192" <cr88...@NOSPAM.hotmail.comwrote:
<kumar...@gmail.comwrote in message

news:47**********************************@j22g2000 hsf.googlegroups.com...
hello:
I recently compiled a numerically intensive c project under cygwin gcc
3.4.4 and microsoft visual c. The platform is intel T2400 1.83 ghz
dual core lap top.
the numerical stuff is both floating point and integer intensive
The gcc optimized (-O3) vs non optimized improved the performance 30 %
visual c optimized (standard , check 'release; under visual c 2005)
vs non optimized ('build') was a whopping 8x performance gain
but the most surprising thing was visual c optimized was 2x
performance over gcc optimized.

likely reason:
MS focuses a lot more on specific optimizations, and tweaking performance
for specific targets;
gcc, however, targets many targets, and tends to use far more generic code
generation (they try more to leverage fancy general purpose optimizations,
rather than arch-specific tweaks for various special cases).

in any case, gcc tends to, fairly often, produce fairly silly code (even
with optimizations), and, sadly, even with a very braindead lower-compiler
design (a hacked over stack machine), and optimizations focusing more on
"common special cases", it is not too hard to match or somewhat exceed gcc's
performance...

IMO, the 'O' options may well be Obfuscate rather than Optimize...

actually, one of the better ways at optimizing, would be likely to implement
a kind of abstract combinatorial tester, which would basically search the
space of possible optimizations and look for the ones with the lowest
simulated cost. sadly though, this will not work so well in the face of
usage patterns, which require actually using the code (the general option
could treat a very common case like an uncommon case, ...).

in something like a VM, it could be possible to use a kind of genetic
evolver for adapting functions (initially, it compiles functions
generically, and any functions it detects are using a significant portion of
the time, it starts mutating in an attempt to improve the general
performance). later, if/when a "final" version is desired, it uses the
versions of the functions found to be most effective.

note that this would likely be confined to the realms of low-level
optimization, with what are typically the biggest time wasters (general
algorithmic issues), being beyond the scope of such a tool...

the simplest approach, however (and the one I currently use in my compiler),
is to basically just test the compiler, and any obvious issues in the output
(silly code), are ones I focus on fixing.

the compiler machinery itself in my case, as this level, is little more than
just a very large and elaborate mass of decision trees (no fancy transforms
or general optimizer machinery, more just operations dispatched through a
maze of function calls).

this approach seems to work good enough IME...
the one silver lining in this affair s because my code is simple, it
shoudl be possible for a compiler guru to zero in on the fundamental
issues and fix gcc

msvc cannot have some voodoo magic on a simple code like that

pardon my layman type of understanding!!

is anybody else seeing the same thing. if this is true microsoft c
compiler is in a different league altogether

that, or, most of us are not that concerned with raw performance (vs having
a compiler we are not obligated to pay for...).

none the less, MS has at least a decent compiler in these regards...
i was not successful so far compiling under mingw. will it make dent ?
2x is hard to overcome

well, with gcc, it is hard to do much better...

as noted, MSVC and Intel are good options...
Jun 27 '08 #13

"Niz" <notarealemailaddresswrote in message
news:20**************************************@news-europe.giganews.com...
On 2008-05-09 22:03:14 +0100, ku******@gmail.com said:
>the problem is in my type of product i have to recommend windows
platform because based on gcc performance an apple to apple linux
platform will run 2x slower

Your using a version of GCC which is 3 years old. Perhaps try with one of
the newer versions with all the relevant optimisations and then see if the
difference is so great. Macs have GCC 4.0.1 (soon to be 4.2.2) as their
base compiler under Leopard.
sadly, I don't expect gcc to be steadily and rapidly picking up efficiency.
this is by no means a new project, and so likely any performance improvement
is likely to be fairly minor.

Although as others have said, the Intel compiler is king of the hill for
producing fast Intel x86 and x86_64 code.
wonder why that is?...

I think:
they make CPUs, so they have more than a few good ideas for how to optimize
them;
they only have to worry about a select few archs (x86, x86-64, and IA64), of
which, they can likely get away using very optimized backends (namely: a
specialized backend for each arch);
they get good money for all this, and have plenty of funds to devote;
....

so, it would be saying a lot if they did not have a compiler which produced
good output...
meanwhile, as for gcc:
it is written by people with apparently more than a few weird ideas WRT
processor efficiency;
it has to target many archs, and use most of the same machinery between a
variety of them;
a good portion of the developers are hobbyists (not that hobbyists can't be
motivated, but many of them likely have other concerns as well);
....

none the less, they are doing pretty well, and gcc is still a fairly good
compiler...


Jun 27 '08 #14
ku******@gmail.com wrote:
) thanx all of you for responding. I was totally unprepared for such a
) vast performance difference (2x msvc vs gcc) and my code is not at all
) special(no UI, complicated classes etc). it simply does lots of
) floating point array(mainly through fft) and normal integer
) operations
)
) I used -O3 flag and in my case so far it seems to be better than O2.
) msvc by default uses their own O2.

Have you tried gcc's -march=native setting, along with possibly
-msse2 and/or -mfpmath=sse, or some other i386-specific settings ?

Normally, gcc will compile a binary so that it will run on any i386,
not only the current machine.

) I cannot believe such a blatant difference will go unnoticed for long
)
) in our type of situation the intel compiler is not an option.
) primarily because we have a standaradized dll plug in architecture
) and so (if windoz do msvc) applies.

SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Jun 27 '08 #15
In message <g0**********@aioe.org>, jacob navia <ja***@nospam.com>
writes
>
It is not surprising that gcc is slower than Microsoft since the
people behind each project have vastly different objectives and
budgets to implement them.

Gcc is running in many platforms and architectures.
Microsoft is running in one platform exclusively.
So Gcc is not likely to be good on any platform as the people who
develop for other platforms will specialise in that and beat GCC?

>Gcc implements standards like C99
CRAP

GCC implements GNU-c and adds extensions for SOME parts of C99
(module small problems), Microsoft
implements only Microsoft environments (.net, etc). Microsoft is
still at C89 level.
Microsoft along with every other compiler INCLUDING GCC is at C95 with
SOME parts of C99 implemented.

GCC is no more C99 than any other compiler.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 27 '08 #16
In article <DY**************@phaedsys.demon.co.uk>,
Chris H <ch***@phaedsys.orgwrote:
>Microsoft along with every other compiler INCLUDING GCC is at C95 with
SOME parts of C99 implemented.
>GCC is no more C99 than any other compiler.
In past posts, people have said that Comeau's compiler with
the Dinkumware libraries are true C99. Certainly dinkumware.com
advertises their library as being fully conforming to standard C99.
--
"Any sufficiently advanced bug is indistinguishable from a feature."
-- Rich Kulawiec
Jun 27 '08 #17
Chris H wrote:
In message <g0**********@aioe.org>, jacob navia <ja***@nospam.comwrites
>>
It is not surprising that gcc is slower than Microsoft since the
people behind each project have vastly different objectives and
budgets to implement them.

Gcc is running in many platforms and architectures.
Microsoft is running in one platform exclusively.

So Gcc is not likely to be good on any platform as the people who
develop for other platforms will specialise in that and beat GCC?
This is very likely indeed. A specialized compiler for a given platform
has less problems and can take advantage of many particular
optimizations that a more general purpose compiler can't use.
>
>Gcc implements standards like C99
CRAP

GCC implements GNU-c and adds extensions for SOME parts of C99
Apparently you can't just say

"I disagree". No. You have to yell

CRAP!!!

Obviously you are right with "Some parts of C99" but those "some parts"
are almost 99% of the job...

>(module small problems), Microsoft
implements only Microsoft environments (.net, etc). Microsoft is
still at C89 level.

Microsoft along with every other compiler INCLUDING GCC is at C95 with
SOME parts of C99 implemented.
I disagree. Microsoft has done no effort at all to implemnt C99. The only
parts they did was // comments and accepting "long long". I am not aware
of any other parts of C99 that they implement.
GCC is no more C99 than any other compiler.
It is more advanced in its implementation of C99 than lcc-win.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jun 27 '08 #18
On May 10, 11:41 am, jacob navia <ja...@nospam.comwrote:
Chris H wrote:
In message <g02blv$63...@aioe.org>, jacob navia <ja...@nospam.comwrites
It is not surprising that gcc is slower than Microsoft since the
people behind each project have vastly different objectives and
budgets to implement them.
Gcc is running in many platforms and architectures.
Microsoft is running in one platform exclusively.
So Gcc is not likely to be good on any platform as the people who
develop for other platforms will specialise in that and beat GCC?

This is very likely indeed. A specialized compiler for a given platform
has less problems and can take advantage of many particular
optimizations that a more general purpose compiler can't use.
Gcc implements standards like C99
CRAP
GCC implements GNU-c and adds extensions for SOME parts of C99

Apparently you can't just say

"I disagree". No. You have to yell

CRAP!!!

Obviously you are right with "Some parts of C99" but those "some parts"
are almost 99% of the job...
(module small problems), Microsoft
implements only Microsoft environments (.net, etc). Microsoft is
still at C89 level.
Microsoft along with every other compiler INCLUDING GCC is at C95 with
SOME parts of C99 implemented.

I disagree. Microsoft has done no effort at all to implemnt C99. The only
parts they did was // comments and accepting "long long". I am not aware
of any other parts of C99 that they implement.
GCC is no more C99 than any other compiler.

It is more advanced in its implementation of C99 than lcc-win.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32
guys:
i have zeroed in and created a simple test program. This progrma just
has floating point addition and integer addition. it does 20 loops x
1million times. in relase version of visual c it takes 0 time. gcc O3
takes 6 secs in my machine.

this cannot be rocket science; there seems to some fundamental
deficiency in gcc. i will treat this as a bug. This should have
serious implications for linux platforms

here is the code; test it for yourself

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

static double loop (long times)
{
long i=0;
double a=0;

for (i=1; i<times; i++)
{
double x1 = i-1;
double x2 = i;
double y = 0;
long n=0;

y = x1+x2;
n = i+ i -1;

y=x1*x2*y;

a=y;
}

return a;

}

int main (int argc, char **argv)
{
unsigned long times = 0;
long i=0;
time_t t=0;
time_t t1=0;
double dt=0;
long lcnt=20;
double a=0;

times = (long) (1e9);

/*
if(argc 1)
{
times = atoi (argv[1]);

times *= 1e6;
}

if(argc 2)
lcnt = atoi (argv[2]);

if(lcnt < 20)
lcnt = 20;
*/
time (&t);

for (i=0; i<20; i++)
{
a = loop (times);
/* you need this for visual c show any elapsed time
printf ("\n %lg \n", a);
*/
}

time (&t1);

dt = difftime (t1, t);

printf ("\n times=%ld loops=%ld dtime = %lg \n", times, lcnt, dt);

exit (0);
}
Jun 27 '08 #19
moi
On Sat, 10 May 2008 09:49:58 -0700, kumarchi wrote:

guys:
i have zeroed in and created a simple test program. This progrma just
has floating point addition and integer addition. it does 20 loops x
1million times. in relase version of visual c it takes 0 time. gcc O3
takes 6 secs in my machine.
:
this cannot be rocket science; there seems to some fundamental
deficiency in gcc. i will treat this as a bug. This should have serious
implications for linux platforms

here is the code; test it for yourself
In gcc 4.1.2, with -O3 , on a 686,
the whole function is elimated and inlined,
leading to :

$ time ./a.out
times=1000000000 loops=20 dtime = 0

real 0m0.001s
user 0m0.000s
sys 0m0.003s
$
In this case, there is no difference in generated code when
-march=i686 -msse2 are added to the -O3 flag.
I guess, you'll have to invent a better benchmark :-)

AvK
Jun 27 '08 #20
ku******@gmail.com wrote:
i have zeroed in and created a simple test program. This progrma just
has floating point addition and integer addition. it does 20 loops x
1million times. in relase version of visual c it takes 0 time. gcc O3
takes 6 secs in my machine.
Here, "cc -O2 try.c" resulted in dtime=0. But "cc try.c" took dtime=280.
Mind you, here "cc" is GCC 4.2.3.
this cannot be rocket science; there seems to some fundamental
deficiency in gcc. i will treat this as a bug.
Be a good idea to raise this issue with the GCC developers, in that case.

Jun 27 '08 #21
Niz <notarealemailaddresswrote:
Although as others have said, the Intel compiler is king of the hill
for producing fast Intel x86 and x86_64 code.
And this tidbit makes Gentoo Linux just that much funnier.
Jun 27 '08 #22
In message <g0**********@canopus.cc.umanitoba.ca>, Walter Roberson
<ro******@ibd.nrc-cnrc.gc.cawrites
>In article <DY**************@phaedsys.demon.co.uk>,
Chris H <ch***@phaedsys.orgwrote:
>>Microsoft along with every other compiler INCLUDING GCC is at C95 with
SOME parts of C99 implemented.
>>GCC is no more C99 than any other compiler.

In past posts, people have said that Comeau's compiler with
the Dinkumware libraries are true C99. Certainly dinkumware.com
advertises their library as being fully conforming to standard C99.

You are correct. Do you know of any other with a FULL implementation .
BTW hands up all those using Comeau's compiler.....

The point is there are no mainstream C99 compilers or any in wide spread
use. Virtually all compilers at C95+ My understanding is that the
next C1* will loose some of the C99 features so C99 may never end up
being implemented in anything other than a few non mainstream compilers

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 27 '08 #23
In message <g0**********@aioe.org>, jacob navia <ja***@nospam.com>
writes
>Chris H wrote:
>In message <g0**********@aioe.org>, jacob navia <ja***@nospam.comwrites
>>>
It is not surprising that gcc is slower than Microsoft since the
people behind each project have vastly different objectives and
budgets to implement them.

Gcc is running in many platforms and architectures.
Microsoft is running in one platform exclusively.
So Gcc is not likely to be good on any platform as the people who
develop for other platforms will specialise in that and beat GCC?

This is very likely indeed. A specialized compiler for a given platform
has less problems and can take advantage of many particular
optimizations that a more general purpose compiler can't use.
>>
>>Gcc implements standards like C99
CRAP
GCC implements GNU-c and adds extensions for SOME parts of C99

Apparently you can't just say
"I disagree". No. You have to yell
CRAP!!!
Well you made a completely false statement of fact.
>Obviously you are right with "Some parts of C99" but those "some parts"
are almost 99% of the job...
Again you are incorrect AFAIK.
>>(module small problems), Microsoft
implements only Microsoft environments (.net, etc). Microsoft is
still at C89 level.
Microsoft along with every other compiler INCLUDING GCC is at C95
with SOME parts of C99 implemented.
I disagree. Microsoft has done no effort at all to implemnt C99. The only
parts they did was // comments and accepting "long long". I am not
aware of any other parts of C99 that they implement.
Actually M$ are, using ECMA, trying to bend standards to be M$ compliant
but that is another story.
>GCC is no more C99 than any other compiler.
It is more advanced in its implementation of C99 than lcc-win.
So what?
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 27 '08 #24
On May 10, 1:18*pm, moi <r...@invalid.address.orgwrote:
On Sat, 10 May 2008 09:49:58 -0700, kumarchi wrote:
guys:
i have zeroed in and created a simple test program. This progrma just
has floating point addition and integer addition. it does 20 loops x
1million times. in relase version of visual c it takes 0 time. gcc O3
takes 6 secs in my machine.
:
this cannot be rocket science; there seems to some fundamental
deficiency in gcc. i will treat this as a bug. This should have serious
implications for linux platforms
here is the code; test it for yourself

In gcc 4.1.2, with -O3 , on a 686,
the whole function is elimated and inlined,
leading to :

$ time ./a.out
*times=1000000000 loops=20 dtime = 0

real * *0m0.001s
user * *0m0.000s
sys * * 0m0.003s
$
In this case, there is no difference in generated code when
-march=i686 -msse2 are added to the -O3 flag.

I guess, you'll have to invent a better benchmark :-)

AvK
ok that was the behavior in visual c. i was using cygwin , i will test
it out in my ubuntu hardy box. thanx
Jun 27 '08 #25
On May 10, 1:18*pm, moi <r...@invalid.address.orgwrote:
On Sat, 10 May 2008 09:49:58 -0700, kumarchi wrote:
guys:
i have zeroed in and created a simple test program. This progrma just
has floating point addition and integer addition. it does 20 loops x
1million times. in relase version of visual c it takes 0 time. gcc O3
takes 6 secs in my machine.
:
this cannot be rocket science; there seems to some fundamental
deficiency in gcc. i will treat this as a bug. This should have serious
implications for linux platforms
here is the code; test it for yourself

In gcc 4.1.2, with -O3 , on a 686,
the whole function is elimated and inlined,
leading to :

$ time ./a.out
*times=1000000000 loops=20 dtime = 0

real * *0m0.001s
user * *0m0.000s
sys * * 0m0.003s
$
In this case, there is no difference in generated code when
-march=i686 -msse2 are added to the -O3 flag.

I guess, you'll have to invent a better benchmark :-)

AvK
you are right; my ubuntu box has gcc 4.2.1 and the gcc in cygwin is
3.4.4. but what a difference!! so my alarm hopefully is a false alarm.
I was also confused my laptop is inter core do t2400 and my hardy box
is amr 4200 x2. and the lapt top + visual c beat out the ubuntu + gcc
in my linux box also. if gcc 4.2.2 can hold up against visual c, then
that means intel beats out amd!!

i will still do more test. and hoep gcc 4.2.2 is a champ. I do not
want to be on teh dark side (=!!
Jun 27 '08 #26
On Fri, 09 May 2008 17:59:22 -0700, kumarchi wrote:

I cannot believe such a blatant difference will go unnoticed for long
Isn't it possible to try out a recent GCC release? After all, GCC 3.4.4
was released way back in may 2005 and the latest GCC is at 4.3.0.
Rui Maciel
Jun 27 '08 #27
ku******@gmail.com wrote:
<snip>
thanx all of you for responding. I was totally unprepared for such a
vast performance difference (2x msvc vs gcc) and my code is not at all
special(no UI, complicated classes etc).
Those are not the types of things which cause modern compilers to stumble.
They seem complex abstractly, but to a compiler are fairly transparent.
it simply does lots of floating point array(mainly through fft) and normal
integer operations
These are things for which compilers are designed to be highly optimized,
and for which failure to enable a seemingly minor feature can cause huge
variance in performance, like you're seeing.
I used -O3 flag and in my case so far it seems to be better than O2.
msvc by default uses their own O2.

I cannot believe such a blatant difference will go unnoticed for long
It's not gone unnoticed, it's merely gone largely uncommented in this group
because this is the wrong group to ask. GCC is not that far behind MSVC. All
the number and graphs I've seen suggest that something else is involved
here.

Yes, you should try GCC 4.x, because GCC 4.x implemented a different
optimization framework. But this probably doesn't account for the 2x
difference.

It's highly likely that the difference you're seeing is a failure to tell
GCC how and which CPU feature sets to target. GCC depends on the build
system to dictate all the various platform-dependent optimizations; because
GCC is often used for cross-compiling, and for various other reasons, that
kind of logic--like CPU-specific optimizations (as opposed to mere
architecture)--is farmed out. It's likely that MSVC, or Visual Studio, is
turning knobs which in GCC must be done manually.

I recommend that you find another newsgroup, or web page, or other
documentation, to help you turn GCC's knobs. The suggestions here, like
-msse, etc, are a _start_, but by no means exhaustive, or even sufficient.
There are lots of flags to know about; for instance, only the very latest
version of GCC 4.x (4.3, I think) automatically vectorizes, but only if you
specify -msse and/or -mtune or something like that. Prior to 4.x, you need
to not only enable the instruction set, but enable vectorizing.

And there are probably tools/applications you can find which will help you
turn those knobs. I'm just not that familiar to give detailed advice. And
while many people are far more knowledgable in this group, you're apt to get
conflicting or confusing advice because this issue isn't the group's focus.
Jun 27 '08 #28
On May 10, 9:49*am, kumar...@gmail.com wrote:
guys:
i have zeroed in and created a simple test program. This progrma just
has floating point addition and integer addition. it does 20 loops x
1million times. in relase version of visual c it takes 0 time. gcc O3
takes 6 secs in my machine.

this cannot be rocket science; there seems to some fundamental
deficiency in gcc. i will treat this as a bug. This should have
serious implications for linux platforms

here is the code; test it for yourself

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

static double loop (long times)
{
* long i=0;
* double a=0;

* for (i=1; i<times; i++)
* * {
* * * double x1 = i-1;
In my very limited experience, optimizers tend to focus on statements
as opposed to declarations. By placing these declarations in the loop
and performing non-trivial computations in the initialization, you
have added an unnecessary "extra level of confusion" to your primary
objective. What happens if you define x1 etc at function scope and
use simple assignment statements here? The initialization for n and y
is superfluous.
* * * double x2 = i;
* * * double y = 0;
* * * long n=0;

* * * y = x1+x2;
* * * n = i+ i -1;

* * * y=x1*x2*y;

* * * a=y;
* * }

* return a;

}

int main (int argc, char **argv)
{
* unsigned long times = 0;
* long i=0;
* time_t t=0;
* time_t t1=0;
* double dt=0;
* long lcnt=20;
* double a=0;

* times = (long) (1e9);

* /*
* if(argc 1)
* * {
* * * times = atoi (argv[1]);

* * * times *= 1e6;
* * }

* if(argc 2)
* * lcnt = atoi (argv[2]);

* if(lcnt < 20)
* * lcnt = 20;
* */
* time (&t);

* for (i=0; i<20; i++)
Shouldn't the limit be lcnt, not 20?
* * {
* * * a = loop (times);
* * * /* you need this for visual c show any elapsed time
* * * printf ("\n %lg \n", a);
printf is a non-trivial function which further camouflages the real
point of your effort. Why not move this out of the loop and change
the function call to
a += loop(times);
* * * */
* * }

* time (&t1);

* dt = difftime (t1, t);

* printf ("\n times=%ld loops=%ld dtime = %lg \n", times, lcnt, dt);

* exit (0);
Jun 27 '08 #29
kumar...@gmail.com wrote:
I recently compiled a numerically intensive c project under cygwin
gcc 3.4.4 and microsoft visual c. ...
... the most surprising thing was visual c optimized was 2x
performance over gcc optimized.

is anybody else seeing the same thing. if this is true microsoft c
compiler is in a different league altogether
Why the surprise? GNU's gcc is intended to be a fast compiler.
It was not designed to produce ultra-fast executables.

--
Peter
Jun 27 '08 #30
Peter Nilsson wrote:
kumar...@gmail.com wrote:
>I recently compiled a numerically intensive c project under cygwin
gcc 3.4.4 and microsoft visual c. ...
... the most surprising thing was visual c optimized was 2x
performance over gcc optimized.

is anybody else seeing the same thing. if this is true microsoft c
compiler is in a different league altogether

Why the surprise? GNU's gcc is intended to be a fast compiler.
It was not designed to produce ultra-fast executables.
I guess you are comparing a current Microsoft compiler (with OpenMP
support) against an obsolete (as stated) gcc version (no OpenMP or
auto-vectorization). I can't see how you can do numerically intensive
work and not be interested in vectorizing compilers, such as current gcc,
or any commercial compiler other than Microsoft.
As this is a C newsgroup, the C++ considerations which limit cygwin to
such an old compiler shouldn't stop you from downloading a current
gcc/gfortran for cygwin.
Jun 27 '08 #31


Barry Schwarz wrote:
for (i=1; i<times; i++)
{
double x1 = i-1;

In my very limited experience, optimizers tend to focus on statements
as opposed to declarations. By placing these declarations in the loop
and performing non-trivial computations in the initialization, you
have added an unnecessary "extra level of confusion" to your primary
objective. What happens if you define x1 etc at function scope and
use simple assignment statements here? The initialization for n and y
is superfluous.
In the compiler tools we write the generated code for the x1 initialization

would be the same size independent of a declaration inside the for loop
or at the function scope.

Initialization in a declaration is handled as if it were a statement and is

optimized as part of the overall optimization. For example
double x1 = i-1;
is the same as if it were written as
double x1 ;
x1 = i-1;

This is probably true in most C compilers.

Regards

--
Walter Banks
Byte Craft Limited
Tel. (519) 888-6911
http://www.bytecraft.com
wa****@bytecraft.com




Jun 27 '08 #32
Barry Schwarz wrote:
kumar...@gmail.com wrote:
.... snip ...
>>
for (i=1; i<times; i++) {
double x1 = i-1;
}

In my very limited experience, optimizers tend to focus on statements
as opposed to declarations. By placing these declarations in the loop
and performing non-trivial computations in the initialization, you
have added an unnecessary "extra level of confusion" to your primary
objective. What happens if you define x1 etc at function scope and
use simple assignment statements here? The initialization for n and y
is superfluous.
If you just stand back and look at that time-waster statement, you
will see that x1 is discarded after the loop and never used, and
that i is set to times. Therefore the optimizer can simply
generate:

i = times;

for the whole loop, and the timing is constant.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #33
CBFalconer <cb********@yahoo.comwrites:
Barry Schwarz wrote:
>kumar...@gmail.com wrote:
... snip ...
>>>
for (i=1; i<times; i++) {
double x1 = i-1;
}

In my very limited experience, optimizers tend to focus on statements
as opposed to declarations.
<snip>
If you just stand back and look at that time-waster statement, you
will see that x1 is discarded after the loop and never used, and
that i is set to times. Therefore the optimizer can simply
generate:

i = times;

for the whole loop,
No it can't. times might be <= 0.
and the timing is constant.
--
Ben.
Jun 27 '08 #34
On May 10, 3:13 pm, kumar...@gmail.com wrote:
On May 10, 1:18 pm, moi <r...@invalid.address.orgwrote:
On Sat, 10 May 2008 09:49:58 -0700, kumarchi wrote:
guys:
i have zeroed in and created a simple test program. This progrma just
has floating point addition and integer addition. it does 20 loops x
1million times. in relase version of visual c it takes 0 time. gcc O3
takes 6 secs in my machine.
:
this cannot be rocket science; there seems to some fundamental
deficiency in gcc. i will treat this as a bug. This should have serious
implications for linux platforms
here is the code; test it for yourself
In gcc 4.1.2, with -O3 , on a 686,
the whole function is elimated and inlined,
leading to :
$ time ./a.out
times=1000000000 loops=20 dtime = 0
real 0m0.001s
user 0m0.000s
sys 0m0.003s
$
In this case, there is no difference in generated code when
-march=i686 -msse2 are added to the -O3 flag.
I guess, you'll have to invent a better benchmark :-)
AvK

ok that was the behavior in visual c. i was using cygwin , i will test
it out in my ubuntu hardy box. thanx
update:

1. I was able to install gcc4.3 in my cygwin laptop

2. I now compared by original program again visual c (release -- uses
ms -O2 option) and gcc
with -O3 -mtune=core2 -march=core2 -msse4.
Visual c is faster by 2.5x!!

3. I try a switch in my program which deploys a different floating
point algorithm. This algorithm is
dominated by floating point additions as opposed to multiplications
in the 'standard' program.
The vc performance does not change. The gcc performance
deteriorates and it is now 3.5x slower than
visual c.

4. I will try to create a simpler test program to represent the above
behavior. My belief is the difference has something to do with the
floating point

i still find it very hard to believe such a huge performance
difference will exist. I can understand 10-20%, not 2.5x to 3.5x

Jun 27 '08 #35
On 30 May 2008 at 16:09, ku******@gmail.com wrote:
2. I now compared by original program again visual c (release -- uses
ms -O2 option) and gcc with -O3 -mtune=core2 -march=core2 -msse4.
Visual c is faster by 2.5x!!
Optimizing a program is an incredibly complex business. There are more
parameters, code paths, trade offs and possibilities than you could
enumerate before the sun becomes a red giant and we all melt off into
oblivion. Why should a factor of 2 surprise you when two completely
different compilers try this task?
3. I try a switch in my program which deploys a different floating
point algorithm. This algorithm is dominated by floating point
additions as opposed to multiplications in the 'standard' program.
The vc performance does not change. The gcc performance deteriorates
and it is now 3.5x slower than visual c.
If you care, disassemble the key routines, and compare what's going on
under the hood. If gcc is doing something obviously silly, submit a
patch to them.
4. I will try to create a simpler test program to represent the above
behavior. My belief is the difference has something to do with the
floating point
Good idea. I believe your proposed explanation makes no sense as stated.

Jun 27 '08 #36
"Ulrich Eckhardt" <do******@knuut.dewrote in message
news:68*************@mid.uni-berlin.de...
jacob navia wrote:
>Microsoft is running in one platform exclusively.

Sorry, but that's untrue. The platforms I know are IA32, Intel's and AMD's
64 bit platforms, MIPS, ARM, SH and maybe some more. Note that the latter
are used for MS' embedded platform.
NT4 ran on a DEC Alpha as well. Also don't forget PowerPC in their XBOX!

;^)

Jun 27 '08 #37
On May 30, 6:59*pm, "Chris Thomasson" <cris...@comcast.netwrote:
"Ulrich Eckhardt" <dooms...@knuut.dewrote in message

news:68*************@mid.uni-berlin.de...
jacob navia wrote:
Microsoft is running in one platform exclusively.
Sorry, but that's untrue. The platforms I know are IA32, Intel's and AMD's
64 bit platforms, MIPS, ARM, SH and maybe some more. Note that the latter
are used for MS' embedded platform.

NT4 ran on a DEC Alpha as well. Also don't forget PowerPC in their XBOX!

NT4 also ran on PPC and MIPS.
Jun 27 '08 #38

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: K. Shier | last post by:
when attempting to edit code in a class file, i see the bug "Visual Basic ..NET compiler is unable to recover from the following error: System Error &Hc0000005&(Visual Basic internal compiler...
1
by: Novice | last post by:
Hi all, I'm afraid this is the second posting of this information as I didn't get a response on the previous post. I will try to shorten my message (i.e. be more concise) in the hopes that it will...
0
by: Rachel Michelson | last post by:
Hello, I have a C++ project that is built using Visual Studio .NET. The source code is configuration-managed in Clearcase so that I build out of a Snapshot view on my Windows XP PC. I am able to...
26
by: Bruno Jouhier [MVP] | last post by:
I'm currently experiencing a strange phenomenon: At my Office, Visual Studio takes a very long time to compile our solution (more than 1 minute for the first project). At home, Visual Studio...
0
by: Bruno Jouhier [MVP] | last post by:
Last september, I posted a message about abnormal compilation times in Visual Studio .NET. I got some help from a nice guy from Sweden, who had the same problem and saw my post on the newsgroup....
6
by: Joachim | last post by:
I made some project changes (which seems it doesn't help if I undo) which have created compilation error: " Server Error in '/PCSWebApp1' Application....
2
by: Tommy Vercetti | last post by:
In Visual Studio .NET 2003, I do the following 1) File->New->Project 2) Visual C++ Projects->.NET->Windows Forms Application 3) Project->Add New Item->C++ File 4) Clear the new C++ file and...
0
by: Ganapathy | last post by:
I have COM dll code written in VC 6.0. When i tried compiling this code in VC 7, The MIDL cmpiler gets called twice. i.e. it initially compiles fully & immediately a line - 64 bit processing'...
2
by: James Zhuo | last post by:
Hi all I've been getting the following compilation error. I should explain the background of the project that i am taking over. This is a project that has been developed by someone else a while...
35
by: mwelsh1118 | last post by:
Why doesn't C# allow incremental compilation like Java? Specifically, in Java I can compile single .java files in isolation. The resulting individual .class files can be grouped into .jar files....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.