473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

VB Code question

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?

Note: I do not wish to cause a battle between C# and VB.Net or VB6
developers here. Just looking for info.

Jul 26 '06 #1
10 1018

<ra******@gmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
>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?

Note: I do not wish to cause a battle between C# and VB.Net or VB6
developers here. Just looking for info.
I could have sworn that you couldn't cast a string variable to an int in
C#....I guess I'll need to try it. In any case, simple casting won't really
speed up an application much. And regardless of language used, it's really
how the app was designed in the first place. Refactoring code would be a
good start. Take a look at some of the methods, see if you could logically
speed them up by rewriting them altogether. Check loops to make sure the
amount of iterations is minimized. Check logic to make sure they are only
performing complex calculations if and when they are needed.

There are a lot of things too look for in order to speed up applications.
Primarily though, the major slow-down that I've pulled my hair out over is
other people's loops. For example, a loop that is set up to find a record.
If they find the record they are looking for, they set a variable that's
declared outside the loop...AND KEEP LOOPING! Why? I dunno, but breaking
the loop right then could save LOTS of time ... just one example :)

Anywho, hth.

Mythran
Jul 26 '06 #2
It seems in my post I just made that I used the term Refractor (If i
remember correctly) out of context. Basically, I mean take a look at the
overall picture of the code you are looking at and see if there's anything
sticking out that doesn't belong. Then take a look at the code piece by
piece...in manageable chunks...

:) Guess I'm just making up words as I go along (or definitions to existing
words)

Mythran
Jul 26 '06 #3
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 have some performance comparisons of CInt, Integer.Parse, Integer.TryParse,
etc at
http://devauthority.com/blogs/jwoole...02/15/747.aspx. In general,
it is often best to try makeing performance comparisons yourself. Also, there
is a point in which you need to balance performance and maintainability.
Sometimes saving 2 ticks isn't worth spending 2 days each time you need to
maintain the code, but in other times it is. Learning to balance these needs
is the art of programming.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Jul 26 '06 #4
Rasta,

It is forever nice that people are searching for performance in looping,
casting, and all those things that takes parts of nanoseconds.

Have a look at how you are using your screen or other external devices. The
repaint of a little part of your screen takes in every system more
performance than millions times those things as I wrote above.

Have you by instance a fancy icon running, have than a look at that, maybe
it is eating up most of your processor time.

Just my first thought,

Cor

<ra******@gmail.comschreef in bericht
news:11*********************@i3g2000cwc.googlegrou ps.com...
>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?

Note: I do not wish to cause a battle between C# and VB.Net or VB6
developers here. Just looking for info.

Jul 26 '06 #5
ra******@gmail.com wrote:
>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?

Note: I do not wish to cause a battle between C# and VB.Net or VB6
developers here. Just looking for info.
The main thing I would look at is object instantiation - it is a
resource killer. Better to have an object hang around for a while
longer than to keep making a new one. That's my 2 cents.

T
Jul 26 '06 #6
IMO the first step would be to try to find out where the time budget is
mostly spent. IMO it's unlikely that a cast or something similar will
produce a visible difference. If you are able to define the area where the
time is mostly spent, you'll be able to give a closer look for possible
improvments (caching, avoiding uneeded work, better algo or whatever else).

--
Patrice

<ra******@gmail.coma écrit dans le message de news:
11*********************@i3g2000cwc.googlegroups.co m...
>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?

Note: I do not wish to cause a battle between C# and VB.Net or VB6
developers here. Just looking for info.

Jul 26 '06 #7
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.
Jul 26 '06 #8
Yes string handling in .net is really terrible!!

Whenever meaningful use always stringbuilder.

Also the try/catch structure, if exceptions really
occurs, is one of the worst things one can put
in a loop: a real suicide... :)

-t

AMercer ha scritto:
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.
Jul 26 '06 #9
ra******@gmail.com wrote:
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
I had an app written for the CF for .Net 1.1. When I recompiled the
app using .Net 2.0 CF, it ran *much* faster. One operation that
normally took about 30 - 40 seconds, now only takes about 5. So in
addition to the other replies, if you can rebuild it for CF 2.0, then
that should help as well.

Jul 27 '06 #10
ra******@gmail.com wrote:
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.
The best statistics are those derived from your application itself. Can
you say which line of code is taking the most processor time? If you
don't know you should find out.

Ex. Casting variables in C# I know the (int)MyStringVariable; is slower
than int.Parse(MyStringVariable);
Considerably slower, since the former doesn't actually compile.
--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Jul 27 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
70
by: grün | last post by:
The MSDN techdocs are somewhat limited on this and I wanted more information. Is there any resource that says definitively which is faster /O2 or /Ox and by how much?
19
by: Rhek | last post by:
Hello, I would like to apologize for double posting this question because I posted this same question in what looks like the VB 6 newgroups and not the .Net newsgroup... Here goes: The code...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
34
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
2
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
4
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
8
by: Andy B | last post by:
Before I do a no no on a newsgroup, I need to ask a question: What is the max number of lines of code you can/should post here before it gets too long?
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.