Quick Search for:  in language:    
article,shows,various,speed,increasing,method
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,290,928. lines
 Jobs: 177. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for Visual Basic.
Diamond Creator - Shows How to Use For Loops
By David Thielke on 11/17


AutoCAD_VB_Bloc kShop1
By Mark Acuna on 11/17


AutoCAD2Excel_V BAExamples2003
By Mark Acuna on 11/17


Click here to see a screenshot of this code!Send message by Address IP
By alireza on 11/17

(Screen Shot)

Click here to see a screenshot of this code!XP Theme Support for Built-in VB Controls
By Vlad Vissoultchev on 11/17

(Screen Shot)

Click here to see a screenshot of this code!Mezclador
By Ronny Fretel on 11/17

(Screen Shot)

Simple Scrolling Banner
By Mike Hayes @Staticnetwork. co.uk on 11/17


Click here to see a screenshot of this code!A simple web browser with a few features
By Mike Hayes @Staticnetwork. co.uk on 11/17

(Screen Shot)

Move a form with any object
By Mike Hayes @Staticnetwork. co.uk on 11/17


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Optimizing your VB code even more

Print
Email
 

Submitted on: 8/7/2001 6:22:50 AM
By: Almar Joling  
Level: Beginner
User Rating: By 45 Users
Compatibility:VB 5.0, VB 6.0

Users have accessed this article 12754 times.
 

(About the author)
 
     This article shows various speed increasing methods, I've done tests myself, you can see the performance difference in a graph and in a table. This article is really worth your time. For example, it shows how one simple "\" instead of "/" will speed up your app with more than 400% percent!

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
Something weird happened with the original tutorial. Probably because of the tables. I don't like to do this, but I really had to upload this awesome article at my website: http://www.quadrantwars.com/optimizations.htm Please vote if you like it. I'm sure you do!


Other 12 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
8/7/2001 8:09:53 AM:Eric Dalquist
Great tips. I've wondered about the speed differences of different styles of VB but never took the time to actually do the test. Glad someone did.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/7/2001 9:52:03 AM:Rick
Good Stuff!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/7/2001 10:10:37 AM:Shawn Elliott
Another very important optimization technique is to reference array items and then use that.<br> example:<br> dim states(0 to 4) as string
states(0) =
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/7/2001 10:11:38 AM:Shawn Elliott
I'll try this again Another very important optimization technique is to reference array items and then use that. example: dim states(0 to 4) as string states(0) = "Alabama" states(1) = "New York" states(2) = "Louisiana" states(3) = "Texas" states(4) = "Illinois" This section here : if len(states(1)) < 5 and mid(states(1),1,1) = "A" then 'Do some freaky thing end if Can be better written as : dim MyState as string MyState = states(1) if len(MyState) < 5 and mid(MyState,1,1) = "A" then 'Do some freaky thing end if The reason you get a performance gain is because you aren't doing an array lookup each time you use the variable states(1). It's worth the extra memory overhead of the new variable
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/7/2001 12:30:57 PM:Almar Joling
Shawn: You're absolutely right. I showed this already a bit with the temporary variables, but I'll add this one as well later =-)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/7/2001 12:35:05 PM:(Tim Miron) yar-interactive software
Well almar, thanks for the follow-up on my article. Hey actually your the guy who's making QW right, i made that splash screen concept remember? hows all that coming? I gota give you five globes on this, i didn't know alot of this stuff my optimization article was a fairly simple "Did you know..." type of jot-note style article... Why didn't you submit this sooner? LOL. Good Job from your "competitor" (I wrote the first optimization article but it wasn't as extensive... however i think it imspired Almar to finally post this article) FIVE GLOBES FOR YOU! Tim PS - get back to me sometime about me helping with QW please... timbo_m45@hotmail.com
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/7/2001 8:37:23 PM:Gary Staunton
Excellent info, would be nice to know when your site is back up.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/8/2001 3:04:21 AM:Igguk
Very interesting! Maybe I can add another trick. I noticed in your examples for loops you use : For I=0 To 10000 Next I Though you can still improve the performance with : For I = 0 To 10000 Next I have never measured the gain you can expect but it's quite important Never repeat the variable after Next, if you want your code to be easier to read, just place it as a comment...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/8/2001 3:45:27 AM:Almar Joling
Igguk: There is no difference between
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/8/2001 5:34:03 AM:Matrix Man
Almar, he means: for i = 0 to 100000 next i is slower than: for i = 0 to 100000 next (note the missing i)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/8/2001 5:47:29 AM:Almar Joling
Hmm, apperently my message got cut off. Anyway, I know what he meant, but there really is no difference in it. It gets converted to an
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/8/2001 6:13:12 AM:Rudy Alex Kohn
I have some more speed up tips, with string handling etc.. Posting them soon - So stay tuned. Oh, Nice artictle ;)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/8/2001 10:03:40 AM:Dave
Great article! Another good tip is to try and use vbNullString instead of "". Example: If strTest = vbNullString Then...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/8/2001 4:43:12 PM:Almar Joling
Hmm, never thought about that one Dave... I might do some testing on that =-)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/9/2001 11:52:42 AM:danda311
You have some nice stuff here, but there is only one problem you throw around longs like there is no tommarow. Longs may be 32 bit, but they are also the largest variable in byte size (Excluding String's cause they vary)., They are as big as variant. So you can use them, but when projects get bigger so does memory usage. I don't care ihave 384 megs of ram but the average household has 64-128. That and the systray is usually loaded also. Thats beside the point though make sure you don't overuse longs. Thank you lates.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/9/2001 12:03:47 PM:Almar Joling
I have to agree partly... Longs are indeed taking up 4 bytes. But if you use them as temporary variable (dimmed in a sub/function), the allocated memory will be free once the sub has been processed. But imagine... 4 bytes. Even if the average household has 64mb (since memory is currently very cheap 128-256 is more likely), you can put 256 longs in 1 kb! Now imagine how many could be filled in a mb. Although that really looks much, hmm... Might be mistaken =-)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/9/2001 12:10:17 PM:Joe
Excellent article. I am always into speeding up code. Never thought about the Left$, Mid$ or Right$.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/9/2001 12:46:43 PM:Srideep Prasad
Excellent Info ! And of course, very useful... I guess you might have spent some time researching and timing the various operations mentioned...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/17/2001 3:44:16 PM:Chris
EXCELLENT! You get 5 start from me :) However, I noticed in the section "Debug.Print" your comment that it still runs. Of course it does. It still runs the function called after the sub, because what if the function did something important? The correct way to test this would be to REMOVE THE Debug.Print AND LEAVE THE FUNCTION CALL.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/26/2001 12:48:04 PM:Rob Wright
Very, very good - congrats.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/23/2001 6:22:49 PM:John Galanopoulos
That's the second excellent post i read from you. This should be part of the Hall of Fame. 5g. Bravo!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/23/2002 8:57:15 AM:Ozan Yasin Dogan
Nice tips, if you want to look a way on how to read / write a file as quick as possible in VB, go on to my submission at: http://www.planet-source-code.com /vb/scripts/ShowCode.asp?txtCodeId=34988 &lngWId;=1
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/23/2002 3:00:09 PM:Mike Christian
Very nice tutorial, Almar. I would be interested to see if there is any speed increase with the following For/Next loop implementation using your criteria: Dim I As Long, L As Long, U As Long L = Lbound(MyArray) U = Ubound(MyArray) For I = L to U Next Since Lbound & Ubound appear to be functions.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/23/2002 7:41:22 PM:peter cant
Nice tips. I had a look at Strcmp before and saw in the help: "vbTextCompare 1 Performs a textual comparison. " How helpful -- not! So thanx for explaining what it does and how it helps.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/24/2002 9:02:20 AM:Gary Choma
Dave, instead of using strTest = vbNullString, use Len(strTest) = 0. It's faster because the string value never get's evaluated. Another thing to keep in mind with optimization: In MOST cases, the savings are negligible (unless extensive looping occurs). It's usually better to write code that's easily understood by another programmer rather than writing something cryptic that executes .2 seconds faster! And when writing code using optimization tricks, it's a good idea to explain what you're doing in comments! Like if I saw "X \ 1" instead of "Cint(x)", it might leave me wondering what's the purpose if it wasn't explained in a comment. Good stuff to know, in any case!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/24/2002 10:51:49 AM:ChoCho
Excellent! I have always wondered about all of that! Thanks!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/24/2002 10:53:57 AM:Almar Joling
I'm not sure why this article attracts so many new people the last few days (I'm the author), but just wanted to say I've updated my original site a LONG time ago, check http://vbfibre.digitalrice.com. Thanks!, Almar
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/27/2002 7:27:28 AM:D.
These are useful tips could be useful to anyone, regardless of level of expertise. Thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/28/2002 9:56:41 PM:Allan
Can't find the article on your site!!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/7/2002 1:21:36 AM:SmartCoder1
Excellent Article! Just out of curiousity how did u get those figures exactly in seconds ?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/20/2002 1:01:10 PM:Mark2
very nicely done, thanks for the tip!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/4/2003 9:50:02 PM:
Cool! good work = 5 globes/stars/circles/ect
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/24/2003 4:04:32 AM:magedsoft
Excellent article. just a question, when you compaired with vs no with, did you have say 10 forms in the project so with may avoide searching through a list or something, I am not the best in programming but just occured to my mind
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.