[AccessD] Classes and Events - EVENTS NOT REQUIRED

jwcolby jwcolby at colbyconsulting.com
Tue Feb 10 23:13:51 CST 2009


Terry,

The results you are getting is most likely explained by the fact that Windows is a multi-tasking 
operating system and is dashing off to process code other than your own, then coming back to give 
your program more time.

It is true that Windows cannot accurately "time" anything.  However the timer class is not useless, 
it still can give you "relative times".  When we program we are constantly searching for bottle 
necks.  I do not care if my timer class tells me to within a millisecond how long something takes 
each and every time it runs, what I care about is that it CAN tell me that process A is so fast that 
it takes essentially no time, whereas query B takes 40 seconds.  That tells me that spending time 
optimizing process A is useless, whereas spending time optimizing Query B may make a tremendous 
difference in how fast my application appears to the user.

Like anything in life, there are those who see lemons, and those who make lemonade.  Your programmer 
friends see lemons, I see a tool that is quite useful, IF you know how to apply it.

In real life I use a framework I built.  I have a form class, and I can time how long it takes for 
my forms to open.  I have a table where I log each and every time a user opens any form.  After a 
few months I now have a very good picture of which users have "slow computers", what the very 
fastest time that any given machine has opened any given form, the longest time that any given 
machine has taken to open any given form, the average time for each machine to open any given form.

This is useful data.  It tells me which forms take a long time regardless of the machine.  It tells 
my client which machines to target with memory upgrades or even replacement as they buy new 
machines.  When I change a query it tells me if I helped or hurt the open times.  All from a timer 
class that can't accurately time anything!!!

I told you that it was not literally a timer, that it simply counted the ticks between things.  In a 
Windows computer, the number of ticks will vary from run to run, quite true, but also quite 
irrelevant for many applications.

And finally, if you truly do need to learn approximately how long some piece of code literally 
takes, then you can always time enough samples and average the samples.  Try to prevent other things 
from running, for example do not defrag your disk while running your code.

Work with what you have and understand the limitations.

 > This operation of Windows (inability to have time to less than 10mS) ...

This is simply not true.  The tick count is in fact 1 millisecond, and USUALLY you will get results 
to 1 millisecond.  There is a whole ton of stuff that goes on in a multi-tasking OS, and yes (I have 
heard) that the time slices given to a given app is 10 ms.  You will NEVER be able to use Windows to 
accurately time anything (code), end of report.  That said, the fact that a 10 millisecond slice is 
given to some app doesn't mean that it necessarily keeps control for 10 ms.  Often times 
applications will know that they are waiting for something to complete and yield back their time to 
the system.

Again though, the fact that your friends need to accurately time something specific and can't use 
Windows to do that does not mean that nothing in the universe can use Windows to discover useful 
information about how long things take.  You and I live in a HUMAN world.  More often than not we 
care about seconds, minutes and hours, not milliseconds.  How long does it take to open a report? 
OK, now how long does it take when I change the query?  Now time it again after making another 
change.  If it is taking 45 seconds and you make a change and now it takes 30 seconds, Windows can 
measure that, and do so to an accuracy that is beyond your requirements to know.

John W. Colby
www.ColbyConsulting.com


MACE, Terry wrote:
> John,
> 
> When I run this I get times of 15,31,16,31,16, 109 or some numbers very
> close to these. Programmers I work with (I'm not one) tell me that while
> the tick count may be a 1mS interval, Windows XP cannot display time at
> anywhere near this resolution and effectively time samples, hence the
> results I'm getting.
> 
> This operation of Windows (inability to have time to less than 10mS)
> prevents them from having a Windows based system for their application.
> 
> Regards
>  
> Terry Mace
> Logistics Support Officer & Maintenance Supervisor



More information about the AccessD mailing list