Re: Why is C# 450% slower than C++ on nested loops ??




"Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in message
news:%23dZslfIDGHA.3844@xxxxxxxxxxxxxxxxxxxxxxx
>
> "Christoph Nahr" <christoph.nahr@xxxxxxxxxxxxx> wrote in message
> news:j4c7r1hvc5lcrmfkndto2724bsnrqe8rk5@xxxxxxxxxx
>> On Thu, 29 Dec 2005 00:19:33 +0100, "Willy Denoyette [MVP]"
>> <willy.denoyette@xxxxxxxxxx> wrote:
>>
>>>[1] This is the correct code which is still ~50% slower than the (corrected)
>>>native C++ code ( __int64 x=0;).
>>
>> Great analysis! This 50% slowdown is also what I've observed in other
>> (non-broken...) mathematical benchmarks of C# vs native C++.
>>
>> For the record, that's also the maximum performance loss I've ever
>> observed; in tasks that aren't as well suited to modern C++
>> optimizers the speed difference is only about 10-20%.
>> --
>
> In this "particular" case, one could conclude that the C# team could have done
> a beter job. However, when looking at the IL produced by C++/CLI and C# you'll
> see that all three produce identical IL (or the loop construct), so there is
> no reason to blame C#.
> However, despite the fact that all managed compilers produce the same IL they
> perform differently:

According to MS technical support this is incorrect. The only reason that one
compiler produces faster code than another is that they generate different CIL.

>
> Same IL
> C#: 100% (verifiable)
> C++/CLI /clr: 64% (non-verifiable)
> C++/CLI /clr:safe : 120% (verifiable)
>
> native C++ : 62%
>
> So you see that in this 'particular case', managed code can perform like
> native code and C# performs slightly better than managed safe C++, but is this
> true in all cases? NO sure not. And that's why you should be careful when
> interpreting benchmark figures, most of the time they have no real value and
> sometimes they are (in a subtle way) incorrect
>
>
> Willy.
>
>


.



Relevant Pages

  • Re: Restart Window Service
    ... (And the code shown is incorrect no matter what the goal is). ... There is no reason to use a wait hint other than 0 if the type is not a _PENDING type ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: Why is it dangerous?
    ... is offensive for some bizarre reason, fine, someone coin another word. ... being called by a name that they considered to be incorrect. ... English deciding that the term "European" ... "European" might apply to others. ...
    (comp.lang.c)
  • Re: howto receive and *understand* via UDP
    ... Doug wrote: ... Your assumed reason is incorrect. ... If I were to say what I thought about it here, nobody ...
    (comp.lang.c)
  • Re: Badly cut out safe areas
    ... >>> uneducated guess is incorrect on this occasion, ...
    (uk.tech.digital-tv)
  • Re: String foreach problem
    ... I didn't say that the reason for reading the text file line by line was ... I'm saying that it appears to me that the goal is what's incorrect. ... you should use Append to turn a binary file into hex digits ... That's why I call long strings a "smell." ...
    (microsoft.public.dotnet.languages.csharp)

Quantcast