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...
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.
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.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
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!
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. (If this comment was disrespectful, please report it.)
Another very important optimization technique is to reference array items and then use that.
example:
dim states(0 to 4) as string
states(0) = (If this comment was disrespectful, please report it.)
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 (If this comment was disrespectful, please report it.)
Shawn: You're absolutely right. I showed this already a bit with the temporary variables, but I'll add this one as well later =-) (If this comment was disrespectful, please report it.)
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 (If this comment was disrespectful, please report it.)
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... (If this comment was disrespectful, please report it.)
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 (If this comment was disrespectful, please report it.)
I have some more speed up tips, with string handling etc.. Posting them soon - So stay tuned. Oh, Nice artictle ;) (If this comment was disrespectful, please report it.)
Great article! Another good tip is to try and use vbNullString instead of "". Example: If strTest = vbNullString Then... (If this comment was disrespectful, please report it.)
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. (If this comment was disrespectful, please report it.)
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 =-) (If this comment was disrespectful, please report it.)
Excellent article. I am always into speeding up code. Never thought about the Left$, Mid$ or Right$. (If this comment was disrespectful, please report it.)
Excellent Info ! And of course, very useful... I guess you might have spent some time researching and timing the various operations mentioned... (If this comment was disrespectful, please report it.)
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. (If this comment was disrespectful, please report it.)
That's the second excellent post i read from you. This should be part of the Hall of Fame. 5g. Bravo!! (If this comment was disrespectful, please report it.)
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. (If this comment was disrespectful, please report it.)
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. (If this comment was disrespectful, please report it.)
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!
(If this comment was disrespectful, please report it.)
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 (If this comment was disrespectful, please report it.)
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 (If this comment was disrespectful, please report it.)
Thanks for the testings you made. Real help. Could you recommend a software I could use for personal testing. I've always wanted to test every aspect of my application but can't find the right tool for it. If you please, email me at Crimson_Zenith@yahoo.com. Thanks! (If this comment was disrespectful, please report it.)
10/15/2004 3:34:02 AM:
Good (If this comment was disrespectful, please report it.)
Excellent article, it was very clear and concise. (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)