.NET Performance Question, Please Reply

D

Don Beal

Thanks to everybody in advance for the replies.

I am somewhat accomplished as a VB 6 programmer (I actually started
with VB 4 about 7 years ago, maybe VB 3 (memory fading :))

I am currently working through a few books, getting to learn C#. It
is not terribly difficult but not nearly as intuitive as VB .NET.

My question is this, if they are both using common language runtimes,
is there anything to be gained by writing in C# instead of VB .NET?
My applications are WMI and network related usually, with some side
projects working with ID3 and SQL stuff.

I chose to use VB6 because it is easier as a RAD tool for me but after
time I found I wanted the stability and robustness of C++. Does this
still hold true for the .NET languages?

Thanks.

db
 
R

Robert Jacobson

There may be minor performance differences here and there between VB.Net and
C#, but performance should be almost identical for comparable code. Keep in
mind that both VB.Net and C# merely generate MSIL (intermediate language),
which is what the CLR actually compiles and runs. As long as the MSIL is
the same, performance will be identical.

The only differences are when you're using some VB-specific function, which
are generally wrappers for .Net framework functions and thus add an extra
level of indirection to your code -- even then, though, the difference is
usually negligable. This article covers this topic in detail:

Visual Basic .NET Internals
http://msdn.microsoft.com/library/d...tml/vbtchMicrosoftVisualBasicNETInternals.asp

In general, you should use whichever language you find most comfortable --
there aren't many pracctical differences between VB.Net and C#. You might
be interested in this ebook:

Dan Appleman, VB.Net or C#: Which to Choose?
http://www.desaware.com/Ebook2L2.htm

Hope this helps,
Robert Jacobson



Visual Basic .NET Internals
http://msdn.microsoft.com/library/d...tml/vbtchMicrosoftVisualBasicNETInternals.asp

--Robert Jacobson
 
D

Don Beal

Thanks Robert for the response and the links. I am a big fan of Dan
Appleman and his books.

Don Beal
 
C

CodeMonkey

Hi,

I've been working with VB6 and VB.net for a while. I'm not an expert,
so don't take my word as gold.
My question is this, if they are both using common language runtimes,
is there anything to be gained by writing in C# instead of VB .NET?

Someone once said: "All .net languages were created equal, so it's
really down to personal preference"

AFAIK, instruction for instruction, all .net languages should preform
exactly the same.

Although each .net language has its own feature set (e.g. C supports
user defined operator functions, VB does not - in the current version
anayway), performance should be the same.

One potential place where performance could differ is where you have
to take more steps to write a function in one language than you have
to in another. For example, in VB.net 2002, bit shift operators were
not supported. If you were writing a function that required bit
shifting, you would have to do a bit of complex math, whereas C#
(probably) has already supported bit shifting. (VB.net 2003 supports
the bit shift operators)

If you are an accomplished VB programmer, my advice would be to stick
with VB - the time you would save because of your past experience with
the language would far out-weigh any missing features the language may
have (besides, I'm sure VB has a few shortcuts that C# doesnt ;-)

Hope thins helps,

Trev.
 
W

William Ryan

Don:

In the short term, learn whichever you feel more comfortable with. In the
long term. Learn them both. Understanding .NET is soooo much more important
than syntax. I think that a top notch VB.NET developer, say Francesco
Balena could learn C# well in a week or two (he undoubtedly already knows
it) but a top notch VB6 programmer couldn't learn VB.NET in anywhere near
that amount of time.

If you use Strong Typing...then there's no real performance differences
between the two. If you don't, the difference is UGLY. That has nothing to
do with VB.NET though, other than it allows weak typing which MS had to
embrace lest they incure the wrath of a whole plethora of programmers that
are too smart and too busy to do things correctly. If you are doing a lot
of API manipluation, C#'s support for unsafe code blocks would probably make
it a 'better' solution, but C#'s case sensitivity can be a real hindrance to
clumsy typists (like yours truly) b/c Intellisense doesn't kick in.

However, and trust me on this...learn .NET. Learn Garbage Collection and
resource management. Learn about strongly typed assemblies and the GAC.
Learn about structured exceptions. In short, focus on the 'big' picture up
front because that's all that matters. Syntax can be learned easily like I
suggest in my example above. But if you still think in err.Code and Goto's
and public variables instead of properties, you're going to pay for it.
ADO.NET is probably the biggest thing that you'll need to deal with too. To
learn ADO.NET, basically, forget all of your ways of dealing with things in
ADO. I know this is a brutal statement to make, but I'd much rather teach a
kid right out of college ADO.NET then many experienced ADO programmers who
are unwilling to part with their old habits (I'm not saying ADO programmers
are like this, I'm speaking to the ones refuse to acknowledge that ADO.NET
ISN'T ADO.)

Don't worry though my friend, it may seem daunting at first, but with a
little patience, you'll learn that a lot of difficult things in VB6 (like
threading) and impossible things (like Windows Services) are much simpler
nowadays (although threading is never going to be 'simple' it is
straightforward).

If I can address anytyhing specific, please let me know.

HTH,

Bill
 
D

Don Beal

Wow! Thanks for the awesome reply.

I parrallel your statement about forgetting ADO to learn it all over
again when I tell people about learning C#. If I had never learned
C++ I think I could pick up C# a lot easier.

I was very fortunate to have taken a data structures class given by a
Microsoft coder a few years back (I think he designed MDAC among other
things) and he was brutal in his demand for proper coding techniques.
This got me to use classes, properties, and UDT's rather than globals
everywhere.

Can you tell me what you mean by "unsafe code blocks", I don't
understand what that means.

Thanks again for the reply.

db
 
D

Don Beal

Thanks for the reply. My boss is very critical of the time-to-market
of my applications (everything is in-house proprietary) so I may just
stick with VB for those and play with C# for personal projects.

db
 
D

David Vins

Don:

I couldn't agree with William more. But just be aware of one pain in the
butt fact -- a large part of the examples you'll come across (and add-ins)
from third parties will seemingly always be in C#.

I've been doing a lot of development work with Microsoft Content Management
Server 2002, and I can't tell you how many of the good examples from others
are limited to the C# paradigm.

Fortunately, I've become accustomed to converting them to VB.NET via handy
tools like http://www.kamalpatel.net/ConvertCSharp2VB.aspx to deal with the
issues.
 
D

Don Beal

Great Website!

Thanks.

db

Don:

I couldn't agree with William more. But just be aware of one pain in the
butt fact -- a large part of the examples you'll come across (and add-ins)
from third parties will seemingly always be in C#.

I've been doing a lot of development work with Microsoft Content Management
Server 2002, and I can't tell you how many of the good examples from others
are limited to the C# paradigm.

Fortunately, I've become accustomed to converting them to VB.NET via handy
tools like http://www.kamalpatel.net/ConvertCSharp2VB.aspx to deal with the
issues.
 
I

Ian

Can you tell me what you mean by "unsafe code blocks", I don't
understand what that means.

Unsafe code is a feature of C# and C++. It allows you to write code that is
not verifiably safe because you are able to directly manipulate pointers.
VB.NET doesn't have this feature and 9.9 times out of 10 it's not something
that you'd miss - the only cases that that I can think of where you might
need it are:

Directly handling binary data structures
Advanced interop
Performance (although few real-world apps will really benefit from this kind
of array/string/etc manipulation ).

HTH

Ian
 
D

Don Beal

Thanks Ian. I just got Dan Appleman's book on VB.NET and that
explained it as well.

Thanks again to everybody for all your great help.

db
 
R

Richard Grimes [MVP]

Don said:
Thanks to everybody in advance for the replies.

I am somewhat accomplished as a VB 6 programmer (I actually started
with VB 4 about 7 years ago, maybe VB 3 (memory fading :))

I am currently working through a few books, getting to learn C#. It
is not terribly difficult but not nearly as intuitive as VB .NET.

My question is this, if they are both using common language runtimes,
is there anything to be gained by writing in C# instead of VB .NET?
My applications are WMI and network related usually, with some side
projects working with ID3 and SQL stuff.


There is a myth that the VB.NET compiler and C# compilers use the same
source code. I doubt it, as I'll explain in a bit. It is possible that
VB.NET and C# compilers can produce different IL for equivalent code,
however, unless you are developing high performance code you'll not see any
difference because it is the performance of the runtime that is important.
Also, the JIT compiler will perform some optimizations and it may optimize
away any difference between the code produced by the two compilers. However,
it is difficult to quantify the effect of the JIT compiler. By profiling
your code you are more likely to improve your performance than by switching
the language. However for raw power you should use native C++, but then you
lose the benefits of .NET (in particular security, which should be number 1
in everyone's list of features).
I chose to use VB6 because it is easier as a RAD tool for me but after
time I found I wanted the stability and robustness of C++. Does this
still hold true for the .NET languages?

The 'robustness' feature is in the runtime: if the runtime is robust then it
does not matter what language was used to create the IL. Indeed, the runtime
validates your IL before it is JIT compiled so that if there are any issues
the IL will not be JIT compiled and hence will not run.

VB.NET is not just C# without semicolons. There are lots more differences
than that. Indeed, in some respects VB.NET is more of a .NET language than
C# is. For example, IL allows 'exception filters', this feature is not
available in C# (IMO for good reason because I don't think they are useful)
but VB.NET does have this feature through the When clause. There are lots of
other areas where C# and VB.NET diverge significantly in their support for
..NET.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top