Re: Managed vs Unmanaged Bare Bones Performance Test

Tech-Archive recommends: Fix windows errors by optimizing your registry



adhingra wrote:

At our company we are currently at a decisive point to choose between managed
and unmanaged code on the basis of their performance.

You need to find a more real-world example, where real-world consists of
one of the typical performance problems that you find in your existing
apps. That is, pick some algorithm you had difficulty optimizing, and
rewrite it in C#.

By basic I mean, just the basic stuff inside the CLR i.e. function calling
cost, for loop, variable declaration, etc. Let us not consider GC, memory
allocation costs, etc.

I'm 100% certain you're not measuring what you think you're measuring
(see below). Your code doesn't do anything, so it can be optimized away
entirely.

Make sure you use a debugger, such as WinDbg (+ SOS) to check the
generated machine code is roughly what you think it should be. Also,
it's a big mistake in a micro-benchmark situation to not actually
aggregate some result and output that result, otherwise you're at risk
of having the whole thing optimized away.

Re function calling cost, consider that simple functions are inlined in
both C# when marked to optimize ('csc /optimize+', be sure not to run
under the debugger) and in typical C++ -O2 implementations. So, for as
simple a function as you're presenting here, you're measuring something
else.

By the way, your C++ program runs in the same time whether it loops
50,000 times or 2,000,000 times, when compiled with VC++ 2005 with cl
-O2. Without further investigation, that tells me that the entire loop
was removed.

-- Barry

--
http://barrkel.blogspot.com/
.