[AccessD] Timer class suggestions...

Bobby Heid bheid at appdevgrp.com
Tue May 9 06:37:51 CDT 2006


Hey,

I had a need to time some code the other day and decided to come up with a
somewhat generic class to help perform this task.  I'd like to ask for your
opinion/suggestions about what I came up with.

This is what I came up with.

First, since all users are on Win XP, I am using QueryPerformanceCounter and
QueryPerformanceFrequency to calculate timings.

There are three classes: clsTimer, clsTimerData, and clsTimerInstance

clsTimer is the main class.  It contains 2 collections that hold instances
of the other two classes and a timestamp of the time that the class was
instantiated (called RunTS).

clsTimerInstance holds data about a timer that has been started (ID, start
value of timer, and a time stamp).

clsTimerData holds the complete timer data record for a given timer event
(ID, start value of timer, end value of timer, difference between end and
start, elapsed time in seconds, time stamp of timer, and RunTS).  This class
holds the completed timer data until the data is persisted.

To use the timers, an instance of clsTimer is instantiated.

For each timer that is to be started, make a call to the clsTimer.StartTimer
with an ID (long value) that  is used as the key for the timer instance.
This function returns an index to that timer that is used to stop the timer.
This function creates an instance of the clsTimerInstance class that
contains the starting values of the timer and adds it to the Instance
collection.

When a given timer is stopped, the ending timer value is obtained.  The
starting values are located in the Instance collection.  A new clsTimerData
instance is created and populated with the timer data and added to the
TimerData collection.  The clsTimerInstance collection item is then deleted.

The data can be persisted to a table with a call to clsTimer.PersistData.
Right now, this function simply iterates the TimerData collection and dumps
it to a table.  I plan on being able to pass this function a value so that
this function can also call two other functions to dump to a formatted flat
file and a CSV file.


To use the timers is a simple as:

Dim cTimer as new clsTimer

...

	x=ctimer.StartTimer(1)
	'some code
	cTimer.StopTimer 1

	x=ctimer.StartTimer(1)
	for i=0 to 100000
		y=cTimer.StartTimer(2)	'we can nest them
		'some more code
		cTimer.StopTimer 2
		next i

	ctimer.StopTimer 1
	ctimer.PersistData

	set ctimer=nothing

The output would look something like (from a different test run):

TimerID StartVal		EndVal	    Elapsed	Seconds TimeStamp
RunTS
1	  215002386.2371	215002420.5905  34.3534	0.096	  5/9/2006
7:32:13 AM  5/9/2006 7:32:13 AM
2 ...
2 ...
2 ...

How does this sound to you all?  Thanks for even making it this far!

Thanks,
Bobby




More information about the AccessD mailing list