YAZ wrote:
Hello,
I have a dll which do some number crunching. Performances (execution
speed) are very important in my application. I use VC6 to compile the
DLL.
A friend of mine told me that in Visual studio 2003 .net optimization
were enhanced and that i must gain in performance if I switch to VS
2003 or intel compiler. So I send him the project and he returned a
compiled DLL with VS 2003.
Your friend is right. VS 2003 and the Intel compiler are the best
compilers available for Windows, regarding speed of generated code.
Optimization has been enhanced. Which surely doesn´t mean that your
programs are always faster. But IMHO shouldn´t be that slower ;-)
Result : the VS 2003 compiled Dll is slower than the VC6 one. For
example the creation of a matrix of 2000000 double random values last
230 ms in the VC6 DLL and 330 ms in the VS 2003.
Is that pure memory allocation and filling or are some floating point
calculations involved ?
Then he compiled the project with intel C++ compiler 9.0 inside VS 2003
with maximum optimization /fast flag and the result is 300 ms.
At last he tried the intel C++ compiler inside VC6 and the result was
200 ms with the /O2 flag. But the DLL generates External exception when
compiled with the /fast flag in VC6.
Curious. Why should the same compiler (Intel 9.0) emit different code
with the same settings in different IDE´s ? Your project settings (VC6 /
VC 2003) must be different. Or did you compile from the command line ?
[...]
Do you have any experience with switching from VC6 to VS2003 ?
I had a look at the generated code ;-) and VC7 (VS2003) optimizes much
better and generates faster code. If you use link time code generation
(global optimization and whole program optimization) the compiler can
use more cpu registers and eliminates function calls and even inlines
code called in different cpp files.
Perhaps you should have a look at the following settings (VC 2003)
a) /O1 is commonly faster
b) RTTI / Exception handling may reduce speed.
c) Security checks (/GS) may reduce (slightly) the performance
(on in release builds)
d) Runtime library (Single / Multithread) has a significant impact
on the speed of e.g. memory allocations and other runtime library
functions
e) Are you using P4 code optimizations ? Though the generated code
runs on P3 processors, it will run slower on non P4 CPU´s.
f) VC 2003 doesn´t use an optimized heap for small memory blocks
on Win2K and upper. I don´t know if this was already the case
for VC6.0. VC 2003 uses the Windows heap instead, to AFAIK prevent
heap fragmentation.
Allocating many small memory blocks might be slower in VC 2003.
It´s one of the reasons why VC 2003 is complained to generate slower
code than other compilers. Though i would recommend to rewrite
the program if the speed difference is due to memory allocation.
Though you may enable the small block memory heap with
_set_sbh_threshold
(But i wouldn´t recommend it generally).
If your program does allocate many small memory blocks and the speed
changes significantly when you are using the function _set_sbh_threshold
i suppose the speed difference is due to changes in the runtime library
and the heap management.
If not - then you should check the project settings. If they are the
same or if you are using the compiler from the command line i can´t
explain the speed difference and i would recommend you to use the
profiler comming with the Intel compiler to find out which part of the
program is causing the speed difference.
Hope that helps.
Andre