I am working with a Compact Framework project that was written in
VB.Net using Visual Studio .Net 2003. That said I have been given the
task of making it run "faster". I am a C# programmer and I know there
are statistics out there for different ways to do the same thing an
which is faster.
Ex. Casting variables in C# I know the (int)MyStringVariable; is slower
than int.Parse(MyStringVariable);
I was wondering if there were such stats for VB.Net like using the
older VB6 type methods of InStr and Mid versus using
MyStringVariable.Contains() or MyStringVariable.SubString()?
Does anyone have a reference for this and maybe how I can improve
performance on an app that was written by a VB6 developer who just
learned VB.Net and applied a lot of VB6 coding practices?
I went through the vb6 to vb.net and faced the same issue. The
documentation contains some guidelines re performance, and in general, you
should follow them. When converting code, I did that except where it meant a
lot of work for little gain.
I also used the profiler nprof (it is freeware, others are available). It
exposes bottlenecks at the function level (not statement level), and that is
all you need for vb.net. It exposed a few things I was doing foolishly in
..net, eg:
1. Making long strings by concatenating many small pieces using the given
string operations. Use stringbuilder instead.
2. Using Mid$ assignments in loops against big strings. This a vb6 natural
that does not perform well in .net. It is similar to #1 above.
3. I was using Debug.Assert(xxx,yyy) in a loop where yyy was an expensive
function call.
I found nprof to be very productive in improving performance. I would run
my program under nprof's control, and examine the tree-like output to find
where I spent the most amount of time. In vb, that usually reduced to a
piece of the vb library, eg mid$ operations. You can look at the code that
calls the offending function and recode a small area. For me, the biggest
offender was sloppy string handling in loops.