Inline.... |-----Original Message----- |From: [email protected] [mailto:ozdotnet- |[email protected]] On Behalf Of silky |Sent: Monday, 17 May 2010 5:44 PM |To: ozDotNet |Subject: Re: How To do something every so often | |On Mon, May 17, 2010 at 3:17 PM, Bill McCarthy <[email protected]> |wrote: |> I'd guess that in a tight loop it would probably be slightly faster to reset |> the counter rather than continually get the modulus, eg: |> |> counter+=1 |> .... |> If (counter And &H2000) = &H2000 Then |> ' every 8192 |> counter = 0 |> End If |> |> By resetting you also don't need to worry about integer overflows etc. | |This is of arguable value
*IN FACT* no it is not of arguable value; you may choose to argue it (no surprises there), but even a 1st year computing student will now the difference between a bitwise And operation compared to a modulus operation is relatively large: Bitwise And is one of the simplest operations, where-as Modulus takes multiple times that of the And operation. You might argue that file IO is significantly slower, so why not make the rest of the code slower but that's a bit like arguing because traffic is slow you drive with your hand brake on ;) | and more confusing then not doing it. <g> I guess bitwise math is confusing to some ;) | It |means if you want to see how many times you've been through the loop Was that asked for ? |you need to keep a seperate counter, | instead of just dividing the |typical one by the loop size. | And ? Do you really think incrementing a separate counter once in every so many thousand iterations is some major overhead? For example, given the &H2000, that means one in every 8192 loops you add 1 to a second counter. I think if you did want to know how many times you updated the UI, a second counter would be exactly what you should use ;)
