Hi Charles,
It depends to a certain extent on what you mean my efficiency. The way I see
it, the first necssity is for the code to do what you want. very fast code
that gets the wrong answer is less useful than very slow code that gets the
right answer.
Once you have code that produces the right answer, you can start thinking of
making it go faster. To decide where to look, you simply work out which
parts of the program are going more slowly than you would like. If you want
to get an accurate measure of the time taken, you can use the CStopwatch
class from Karl Peterson. Go to
www.mvps.org/vb/, click on the Samples link
on the left, and then scroll down the page until you come to the Stopwatch
section.
Having found the slow code (particularly if it is a loop that is repeated
many times), you then have to decide what, if anything, can be done about
it. Sometimes, the code is already optimised as far as possible. But often
there are things you can do, including but not limited to the following
1. Anything that can be taken out of the innermost loop of a nested series
of loops should be.
2. Drilling in to the Word object model should be minimised. If you are
repeatedly reading the same information from the document, read it once, and
put it into a variable and read that in future.
3. If you are using the Selection object a lot to move around the document,
replace it wherever possible with object variable of type Range.
4. If you are building lots of long strings, consider using Karl Peterson's
CStringbuilder class (same location as his stopwatch class) instead of lots
of commands in the form string1 = string1 & string2
In Word programming, these are the most common aspects that can be speeded
up.
--
Regards
Jonathan West - Word MVP
http://www.multilinker.com
Please reply to the newsgroup
Hello,
Is there a process, technique or tool to use, to test the efficiency &
performance of the code being written?
If there is, how does one get it.
What other processes or techniques can be used to test the efficiency of
code???