Re: Efficiency question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Greg (anonymous_at_discussions.microsoft.com)
Date: 08/19/04


Date: Thu, 19 Aug 2004 10:44:55 -0700

Peter,

Thanks for the explaination. I am not really doing
anything for efficiency or any practical purpose for that
matter. I just experimenting with a macro for the
learning experience. It has become quite a hairball as it
grows.
 
>-----Original Message-----
>Hi Greg
>
>Without trying to overly complicate the issue I'll make
the following statement: "You
>don't always just code for efficiency". Sometimes it's
more appropriate to write for
>clarity. I prefer the first version as it does not
duplicate code as the second example
>does. Also I hate the use of the colon (line continuation
character). The only time you
>should use this is to make your code more readable and in
this case it achieves the
>opposite.
>
>Unless the loops running thousands of time I wouldn't
worry too much about efficiency! If
>you're looking for efficiency, you may do better with
something like:
>
> Dim hciDefault As Word.WdColorIndex
> Dim boolHighlight As Boolean
>
> ' Set this outside the loop as it saves an object
repeated reference
> hciDefault = Options.DefaultHighlightColorIndex
>
> ' Do this outside the loop as it saves a repeated
comparison
> boolHighlight = pHlight = vbYes
>
> ' I've removed the True comparison but the compiler
may remove it anyway
> Do While .Execute
> If boolHighlight Then
>
> ' Use with so save a repeated object reference
> With rngStory
> .HighlightColorIndex = hciDefault
> .Collapse wdCollapseEnd
> End With
> End If
> pCount = pCount + 1
> Loop
>
>to be quite honest, given the overhead of having Word
searching a document the
>optimisation is truly redundant.
>
>HTH + Cheers - Peter
>
>
>"Greg" <anonymous@discussions.microsoft.com>, said:
>
>>I am reviewing my code looking for efficiencies.
>>
>>The code looks for text, counts occurrences, and "if"
the
>>user elects, it will highlight each occurrence.
>>
>>Here is a bit of code that is working, but seems
>>inefficient:
>>
>>Do While .Execute = True
>> If pHlight = vbYes Then
>> rngStory.HighlightColorIndex _ =
>> Options.DefaultHighlightColorIndex
>> rngStory.Collapse wdCollapseEnd
>> End If
>> pCount = pCount + 1
>>Loop
>>
>>Since pHight is set before the Do ... Loop starts, and
>>won't change during the Loop am I not wasting time
>>checking it each run through the Loop?
>>
>>Would it be more efficient to have two Do ... Loops in
an
>>IF Else statement like this:
>>
>>If pHlight = vbYes Then
>> Do While .Execute = True
>> rngStory.HighlightColorIndex _ =
>> Options.DefaultHighlightColorIndex
>> rngStory.Collapse wdCollapseEnd
>> pCount = pCount + 1
>> Loop
>>Else: Do While .Execute = True
>> pCount = pCount + 1
>> Loop
>>End If
>>
>>I think I am asking a stupid question with an obvious
>>answer. Just looking for confrimation that I am on the
>>right track here or a recommendation for a better way.
>>
>>
>
>.
>



Relevant Pages

  • Re: How to copy multi object array contents into single object arrays?
    ... For people used to C-style languages, that loop will feel quite ... ECMAScript save the implicit conversion!), and in C99 you would use ... `i--' for maximum efficiency. ... The ascending order and the unnecessary pushcalls will decrease ...
    (comp.lang.javascript)
  • Re: How to copy multi object array contents into single object arrays?
    ... languages most recognizable for blocks delimited with curly braces. ... hoisting the loop bound.) ... As to the efficiency claims, ... I see differences in integer array look-ups, ...
    (comp.lang.javascript)
  • Re: Passive reradiating antenna
    ... loop the efficiency remains the same. ... > ferrite core material. ... For small permeabilities the capture area is much increased. ...
    (rec.radio.amateur.antenna)
  • Efficiency of returning big objects
    ... I had a concern over the efficiency of returning big types, ... Iters: Natural; ... while Clock - Start < 1.0 loop ...
    (comp.lang.ada)
  • Re: MMC64 Mounted Internally
    ... few hundred bucks before I go experimenting? ... Another approach is to get a cartridge ... port extender ribbon cable, and just loop the ribbon cable back inside the ...
    (comp.sys.cbm)