Numerics: Visual C++ vs. g++



I have been working for long time with g++ but for some internal
matter I have to use Visual C++ Express Edition now. I have made quick
tests with my code in C and C++ that implements the naive
multiplication of matrices

http://matrixprogramming.com/MatrixMultiply/code/2direct/

with the goal to see how the compiler optimizes the loops. My commands
to compile and run tests are in the make file compare and

make –f compare

compiles and runs tests with GCC and Visual C++. Below there are
results with gcc 3.3 under Cygwin and Visual C++ Express Edition 2005
at my HP notebook

$ make -f compare

gcc -s -O3 -Wl,--stack=50000000 direct1.c -o direct1-gcc.exe
direct1-gcc.exe
time for C(1000,1000) = A(1000,1000) B(1000,1000) is 2.453000 s

cl -O2 -nologo direct1.c -link -STACK:50000000 -out:direct1-vc.exe
direct1.c
direct1-vc.exe
time for C(1000,1000) = A(1000,1000) B(1000,1000) is 1.984000 s

gcc -s -O3 -Wl,--stack=50000000 direct2.c -o direct2-gcc.exe
direct2-gcc.exe
time for C(1000,1000) = A(1000,1000) B(1000,1000) is 2.047000 s

cl -O2 -nologo direct2.c -link -STACK:50000000 -out:direct2-vc.exe
direct2.c
direct2-vc.exe
time for C(1000,1000) = A(1000,1000) B(1000,1000) is 1.985000 s

g++ -s -O3 direct.cc -o direct-gcc.exe
direct-gcc.exe 1000
time for C(1000,1000) = A(1000,1000) B(1000,1000) is 2 s

cl -EHsc -O2 -nologo -DUSECLOCK direct.cc -link -out:direct-vc.exe
direct.cc
direct-vc.exe 1000
time for C(1000,1000) = A(1000,1000) B(1000,1000) is 6.969 s

One sees that for the C code VC produces a slightly faster code but in
the case of C++ code it is slower more than 3 times. I am new to VC++
and I guess that there are some specific flags to optimize the C++
code. I am searching now in Help but so far unsuccessfully. I would
appreciate any hint in this respect, as it is quite painful to loose a
factor of 3 in a simple loop.

Best wishes,

Evgenii
.



Relevant Pages

  • Re: Numerics: Visual C++ vs. g++
    ... Microsoft VC6 compiler and sometimes the Visual ... make ?f compare ... compiles and runs tests with GCC and Visual C++. ...
    (sci.math.num-analysis)
  • profilling help
    ... I am playing with some optimization options for c++. ... I just change all loops in ... optimization) gcc actually gets me triple the runtime for some reason. ... compiler gives me runtime and call count information for all functions but gcc ...
    (Debian-User)
  • Re: Benchmark (Phoronix): FreeBSD 9.0-RC2 vs. Oracle Linux 6.1 Server
    ... I extended the gcc part a little bit to make it a little bit more clear when it matters. ... If you compare FreeBSD / GCC 4.2.1 against, for example, Ubuntu / GCC ... To compare it with Formula1 cars. ... some local modifications and fixes) as the system compiler. ...
    (freebsd-current)
  • Re: kernel + gcc 4.1 = several problems
    ... -- It is an important optimisation for loops with a signed ... Compiler developers always make the mistake of overrating ... If GCC does really poorly on a few important loops that matter, ...
    (Linux-Kernel)
  • Re: Benchmark (Phoronix): FreeBSD 9.0-RC2 vs. Oracle Linux 6.1 Server
    ... If you compare FreeBSD / GCC 4.2.1 against, for example, Ubuntu / GCC ... To compare it with Formula1 cars. ... some local modifications and fixes) as the system compiler. ...
    (freebsd-current)