Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is C# supposed to run faster than VB.Net? 1

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
Is C# supposed to run faster than VB.Net?

Or are they, more or less, the same?

They both just the .Net Framework, and the same JIT Compiler, so are there any differences in speed?

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
As you've said, both C# and VB.NET are compiled to MSIL, and when executed it is the MSIL that is JIT compiled.

If there is a difference, it is in the C# and VB compilers - one maybe slightly more efficient than the other.

IMHO, there is no noticable speed difference when executing the same project from either C# or VB.NET source.
 
Based on all the material I've read so far, the two languages are supposed to be pretty much equal. C# has pointers and operator overloading while VB.NET doesn't but that's about it!

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
Depends on if both code uses the same functions. If the VB.NET code makes use of the Microsoft.VisualBasic namespace, it will be slower, as those methods are (often) just wrappers for existing .NET methods, adding an unnecessary layer.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I had just read something on MSDN right after I posted the Q...

It appears that the languages are, more or less, the same, except for the syntax...


With ASP.NET, developers can choose to create the server-side code for their Web pages in a myriad of languages. The most common languages that developers will choose, will likely be VB.NET or C#. (There are a number of other languages one can choose to use, from Perl.NET to JScript.NET to COBOL.NET.) Of the many ASP.NET articles and code examples that exist on the Web, it seems that while a slim majority of them are shown VB.NET, a good number are written in C#.

What language is the "best" language choice? If you are a VB wizard, should you take the time to learn C# or continue to use VB.NET? Are C# ASP.NET pages "faster" than VB.NET ASP.NET pages? These are questions that you may find yourself asking, especially when you're just starting to delve into .NET. Fortunately the answer is simple: there is no "best" language. All .NET languages use, at their root, functionality from the set of classes provided by the .NET Framework. Therefore, everything you can do in VB.NET you can do in C#, and vice-a-versa. The only differences among languages is merely a syntactical one.

If you are more familiar with Java, JScript, or C/C++, you may find C#'s syntax more familiar than VB.NET's. If you've been doing VB for the past five years, there's no reason to think you have to now switch to a new langauge (although you should always look to be learning new things).

I thought that you could overload in VB... (maybe I was thinking about C#)

However, you can in the new VB.Net (2005)

The beta is available as a free download, and IMO is MUCH better than 2003...

I did not know that the Microsoft.VisualBasic namespace slowed things down...

Thanks for all the replies,
-Josh

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Most programmers using C# probably come from the C/C++ camp where type checking was not left to the compiler but the programmer; obviously VB does take extra steps to do it for you and thus might take extra code.
 
marinero makes a good point. C# is a type safe language, in that variables must be declared with a specific type. In VB.NET, you can turn off Option Strict which allows unsafe type declaration. The compiler must then use some means of determining what type the variable is - sometimes this requires using the System.Reflection namespace - which involves extra code.
 
Reflection is ummm, rather slow. It's best to be sure of what your datatypes are. Exceptions would be made for doing things like calling thru an Interface, where you don't know/care what the specific type is.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Yeah Chiph, I certainly wasn't advocating switching off explicit type declaration in VB.NET - in fact the opposite. My rule here at work is that any developer using Option Strict Off gets the doughnuts for a week....
 
and does he have to eat them all?

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
On the type issue...

Yes, I noticed that...

The one issue I have been dealing with is Objects...

the AutoCad and SolidWorks API's deal with object in an unusual way...

a function might return one object at one point, and a different one at another call...

So you have to use the Object type...

in C#, this takes extra code, because you have to do the type casting yourself...

Such As:
Code:
            AutoCAD.AcadApplication acApp;
            try
            {
                [b]acApp = [COLOR=red](AutoCAD.AcadApplication)[/color]Marshal.GetActiveObject("AutoCAD.Application");[/b]
            }
            catch
            {
                acApp = new AutoCAD.AcadApplication();
            }
            AutoCAD.AcadDocument Dwg;
            double[] pt1 = new double[3] {0,0,0};
            acApp.Visible = true;
            Dwg = acApp.Documents.Add("");
            Dwg.ModelSpace.AddText(TextBox1.Text, pt1, 1);

Where the VB.Net (2005) code looks like this...
Code:
        Dim acApp As AutoCAD.AcadApplication
        Dim Dwg As AutoCAD.AcadDocument
        Dim pt1(2) As Double
        Try
            [b]acApp = GetObject(, "AutoCAD.Application")[/b]
        Catch ex As Exception
            acApp = CreateObject("AutoCAD.Application")
        End Try
        acApp.Visible = True
        Dwg = acApp.Documents.Add("")
        Dwg.ModelSpace.AddText(TextBox1.Text, pt1, 1)


Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top