|
|
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 |
|
|
Your Vote! |
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.
|
8/7/2001 9:52:03 AM:Rick Good Stuff!
|
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) =
|
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
|
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 =-)
|
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
|
8/7/2001 8:37:23 PM:Gary Staunton Excellent info, would be nice to know
when your site is back up.
|
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...
|
8/8/2001 3:45:27 AM:Almar Joling Igguk: There is no difference between
|
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)
|
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
|
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 ;)
|
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...
|
8/8/2001 4:43:12 PM:Almar Joling Hmm, never thought about that one
Dave... I might do some testing on that
=-)
|
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.
|
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 =-)
|
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$.
|
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...
|
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.
|
8/26/2001 12:48:04 PM:Rob Wright Very, very good - congrats.
|
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!!
|
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
|
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.
|
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.
|
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!
|
6/24/2002 10:51:49 AM:ChoCho Excellent! I have always wondered about
all of that!
Thanks!
|
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
|
6/27/2002 7:27:28 AM:D. These are useful tips could be useful
to anyone, regardless of level of
expertise. Thanks
|
7/28/2002 9:56:41 PM:Allan Can't find the article on your site!!!
|
10/7/2002 1:21:36 AM:SmartCoder1 Excellent Article! Just out of
curiousity how did u get those figures
exactly in seconds ?
|
12/20/2002 1:01:10 PM:Mark2 very nicely done, thanks for the tip!
|
1/4/2003 9:50:02 PM: Cool! good work = 5
globes/stars/circles/ect
|
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
|
|
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. |
|