Alex Rivera | Logout

Why do .net languages vary in performance?

Asked 2011-06-28T15:40:55.913
19

I have heard that C++ .NET is fastest , C# is next, followed by VB .NET and Languages like Iron-Python and Boo come last in terms of performance. If all .NET languages compile to intermediate byte-code which is the same, why the difference in performance?

It is understandable for Boo and Python as all the types have to be evaluated at runtime. But why the difference between languages like C++ and C#?

Edit
Report

1 Answer

1

Following C++ instincts in C++/cli will lead to faster code than using C# instincts in C#, e.g. when looping through data. Sure, You CAN use unsafe C# code to accomplish the same thing and you CAN use arrays in C++/cli, but if instead you follow fairly standard language paradigms there can be a huge performance difference in the right circumstances, e.g. 10 to 1 in a tight loop with plenty of data access.

C++ paradigm in C++/cli

char * position = start;
char * end = position + data_count;
while ( position < start ) {
     { do stuff with the data )
     position ++;
}

C# paradigm

for ( int i = 0 ; i < count; i ++ ) {
    { do stuff with data[i] )
}

Use the dissassembly window and you will see how very differently these compile.

Besides these programming paradigm issues there may be actual compiler issues, but I don't know anything about those.

answered 2011-06-28T19:34:54.853

Your Answer