Re: optimized code



All depends on what exactly you are measuring , how you are comparing and
what you are expecting.
But suppose we are talking about code generated by MSFT VS2005 C#, C++ and
C++/CLI, first, you should understand that you are basically using the same
math library (the CRT library) for all three. That means that the results
should be comparable for both C# and C++/CLI, and that C++ should take
advantage of the back-end optimizer which can do a better job than the JIT
compiler.
Anyway what I have measured so far using VS2005, is a slight advantage (<
5%) for C++/CLI over C# and a larger advantage (<20%) for C++ oner C#.

The difference between C# and C++/CLI is due to a better optimized IL
produced by the C++ compiler, when enabling max. optimizations (enables the
fastest FP unit mode).
The difference between managed and unmanaged C++ is due to the extra
redirection (through the CLR) between managed code(well, JIT'd ) and the
math library.
Note that your mileage may vary, therefore, I would suggest you do your
homework, run some benchmarks, compare and make a language decision. Note
however, that performance should never be the only criterion to select a
development language (or platform). Remember faster is not always better,
especially when talking about FP arithmetics.


Willy.


"Fred Mellender" <nospamPlease_fredm@xxxxxxxxxxxxxxx> wrote in message
news:YTxlf.702$EE4.354@xxxxxxxxxxxxxxxx
> Can anyone comment on C# vs. C++ for floating point performance with V2?
>
> In
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetperftips.asp
> we
> read:
>
> "Floating Point?The v1 JIT does not currently perform all the FP-specific
> optimizations that the VC++ backend does, making floating point operations
> more expensive for now. "
>
> Has this been improved? Can anyone quantify the difference in
> performance. I have a highly computation-intensive program written in C#
> and wonder what the difference would be if I were to rewrite in C++.
>
> "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in message
> news:uhWpH9r%23FHA.2472@xxxxxxxxxxxxxxxxxxxxxxx
>>
>> "Daniel O'Connell [C# MVP]" <onyxkirx@xxxxxxxxxxxxxxxxxxxxx> wrote in
>> message news:eNZ5Ljq%23FHA.1676@xxxxxxxxxxxxxxxxxxxxxxx
>>>
>>> "Mike" <vimakefile@xxxxxxxxx> wrote in message
>>> news:Oj7acNp%23FHA.2424@xxxxxxxxxxxxxxxxxxxxxxx
>>>> Is it still true that the managed C++ compiler will produce much better
>>>> opimizations than the C# compiler, or have some of the more
>>>> global/aggressive opimizations been rolled into the 2005 compiler?
>>>>
>>>
>>> Yes, the Managed C++ compiler should still be better. the C# compiler
>>> still doesn't go very far as far as optimizations go, AFAIK anyway. They
>>> are left to the JIT.
>>>
>>>
>> The same applies to the "managed C++" compiler, common sub-expressions
>> and loop invariants are handled by the JIT not by the compiler fron-ends.
>> The managed C++ compiler generates IL, sometimes it does a better job,
>> but I've seen IL code that was better optimized by the C# compiler.
>> Anyway the differences are < 5% (both sides), MS said that they will
>> focus on the JIT to further optimize, not in the C++ front-end.
>>
>>
>> Willy.
>>
>>
>
>


.



Relevant Pages

  • Re: optimized code
    ... > loop invariants are handled by the JIT not by the compiler fron-ends. ... generates the best optimized MSIL of any of the .NET languages. ... standard native code optimizations on MSIL code. ...
    (microsoft.public.dotnet.languages.csharp)
  • misc: lang effort, performance
    ... I added a define that allowed me to enable/disable ref counting to see what ... a c implementation of the algo takes about 110ms (generic compiler options). ... I had started to consider the possibility of jit compilation. ... of course, thinking of it, some optimizations (those which I had originally ...
    (comp.lang.misc)
  • Re: C# and compiler optimizer.
    ... letting you specify inlining? ... A JIT can just start by running the optimizations a traditional compiler would do. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: optimized code
    ... the Managed C++ compiler should still be better. ... > are left to the JIT. ... I assume the JIT is limited to peephole optimizations? ... If I have an inner loop of something like: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: WaitForSingleObject() will not deadlock
    ... One is to hijack the semantics of volatile to disable compiler optimizations ... and otherwise let the compiler to agressive optimization. ... Agressive optimizations are the ones that work on the edge of the semantics of the ... Because the compiler can see into lock and unlock, it is able to reduce f ...
    (microsoft.public.vc.mfc)