|
-
Dec 5th, 2005, 04:36 PM
#1
Thread Starter
Hyperactive Member
C# and VB
Which is faster? I know C++ is the fastest but I know C# is basically a managed C++. Correct me if I'm wrong because C# is a language I am becomming more interested everyday. Is C# faster performancewise or is it basically just another way to write code?
Thanks to all who reply!
Taco
-
Dec 5th, 2005, 04:45 PM
#2
Re: C# and VB
C# is not a managed C++. C++.NET is managed C++. C# is no more managed C++ than Java is. They are both languages that are based on C/C++ syntax but they are both quite different as well. Generally speaking, a VB.NET app that does the same thing as a C# app will perform exactly the same. They both get compiled to MSIL, and often exactly the same MSIL. C# provides some features that make it easier to write code that will perform faster, like the use of pointers in unsafe code blocks, but in general usage most developers won't use them anyway. I've written a fair bit of C# code and never used a pointer. The language was designed in such a way that you normally don't need to. You can speed up certain operations considerably by their use, but the same issues exist with pointers in C# as do in C++, which is why they are a bonus in certain situations but it's probably preferable to avoid them in general.
-
Dec 6th, 2005, 10:00 PM
#3
Hyperactive Member
Re: C# and VB
Good post.
I'd also like to point out a thing I read. C# and VB.NET have the opportunity to be absolutely identical in speed.
However, in practice C# will get a very very tiny edge. The reason is because of the verboseness of the VB.NET language. The structures are broken out to multiple statements internally.
Example:
VB.NET
VB Code:
For i as Integer = 0 to 10
'Some code
Next
When the above is compiled into MSIL it is actually expanded to:
Code:
int i;
i=0;
while(i <= 10)
{
'some code
i++;
}
Meanwhile, in C#
Code:
for(int i = 0 ; 0<=10 ; i++)
{
//some code
}
The above statement is translated more cleanly and efficiently because there is no need to translate the word like structure into IL.
-
Dec 7th, 2005, 10:02 AM
#4
Re: C# and VB
Here are some differences
http://thecodeproject.com/dotnet/vbvscsmsil.asp
Bear in mind that even different IL usually gets compiled to the same native code by the JIT compiler.
-
Dec 14th, 2005, 09:49 AM
#5
Re: C# and VB
If you were to use the VisualBasic namespace your application would probably compile to slower code than a C# version, but of course if you do everything the global .NET way that's not a problem.
Pointers aside Unsigned Ints are available in C# which makes a difference in large for loops, however i think they allowed the use of UInts in VB.NET 2005?
In my opinion alot of it comes down to the way you code, if you do it scrappy in C# it is still going to be worse than if it was done properly in VB.NET
Personally I like writing my applications in both, front-end VB.NET and DLLs in C# for large operations. I find basic syntax suits form manipulation, and the c format suits data manipulation.
-
Dec 14th, 2005, 11:52 PM
#6
Re: C# and VB
 Originally Posted by Phill64
Personally I like writing my applications in both, front-end VB.NET and DLLs in C# for large operations. I find basic syntax suits form manipulation, and the c format suits data manipulation.
One of the nice things about .NET and Visual Studio is that you have the freedom to make that choice. Applications and libraries written in different languages have always been able to interact, but it's never been as easy and well integrated as it is in recent VS releases.
-
Dec 16th, 2005, 09:27 PM
#7
New Member
Re: C# and VB
As far as .Net goes you may want to take a look at the book I included at the bottom of this post. I realize your question is reguarding C++ vs. C#, however, I still think this book might come in handy because it describes the .Net Framework in some detail.
As a general rule Microsoft claims in several articles and in this book that all .Net languages are supposed to execute at the same speed because they are all compiled to the same MSIL. But I'm sure there are differences here and there that may make one language a little faster then another. It all depends on the code you need to write.
I think the point here is to choose the language you are the most fimiliar with. Don't choose C++ just because it may be the fastest language compaired to C#. C++ may be faster but if your code is written like crap, then it may actually end up being a lot slower then C#.
Choose the language that makes you more productive.
I'm not sure how much this book will help in your case, but its worth taking a look at. If you can get it from your local library for free.
MCAD/MCSD
Developing Windows-Based Applications
Microsoft Press
ISBN: 0-7356-1926-3
- Billiard
If you would like me to read your code, please use [code] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|