R – Strange performance increase in projects compiled in VS 2008 comparing with VS2005

command-line-interfaceperformancevisual-studio-2005visual-studio-2008

I have a 3rd party library and a simple benchmark test that I write by myself to test this library for performance. 3rd party library is C++/CLI .NET library and most code there is unmanaged. This library is assembled for .NET Framework 2.0. My benchmark test is managed C# code that adds little overhead to the library, only simple calls to the methods, subscription to event handlers, closing/opening connections etc. Library performs some operations in multiple working threads, it also deals with sockets.

Strange thing – when I compile by benchmark test with VS 2005 and when I do the same with VS 2008 – I got different performance values (VS 2008 is 10% better).

What can cause the performance increase, if all my code uses only .NET 2.0 features, no language/features or libraries from 3.5 are used. My benchmark project refers only System.dll and 3rd party dll, and benchmark code is absolutely the same in VS2005 and VS2008 projects ?

Best Answer

Even if you only use 2.0 functionality (language? Library?), it can be that 3.5 JIT simply optimizes the code, or that some of the libraries are more optimized.

In other words: while the interfaces of 2.0 functions remain the same backwards compat, that doesn't have to be the case for the implementation. I assume the GC (and its locking is also constantly tweaked)

It will be very hard to figure out what exactly causes the difference. It could be as simple as some primitive functions (like memmove, search for byte/word in mem) being optimized for more recent cpu's.