Christopher Hawkins
clh at christopherhawkins.com
Thu Feb 10 12:05:11 CST 2005
Just FYI...does this time class of your avoid the "flicker" the typically accompanies the resetting of a Form object's TimerInterval property? If so, I will use your code until the end of my days! ;) -Christopher- ---------------------------------------- From: "John W. Colby" <jwcolby at colbyconsulting.com> Sent: Wednesday, February 09, 2005 10:36 PM To: "'Access Developers discussion and problem solving'" <accessd at databaseadvisors.com> Subject: [AccessD] Article for DBA newsletter / website I am writing an article for DBA's new website content (and maybe a newsletter, not sure exactly). May I suggest that anyone out there interested in being published do the same. Contact Jim Lawrence if you would like to contribute code or articles. At any rate, as you might imagine I am going to do a class demo, a timer. If you've been around the group long you have seen the class. It is a variant of old ADH code and looks like: Option Compare Database Option Explicit ' 'This class is so simple that I will not use the normal class framework interface. 'This class never loads children, never does anything that should cause problems 'so the framework interface is generally unneeded. ' Private Declare Function apiGetTime Lib "winmm.dll" _ Alias "timeGetTime" () As Long Private lngStartTime As Long 'THESE FUNCTIONS / SUBS ARE USED TO IMPLEMENT CLASS FUNCTIONALITY '*+Class function / sub declaration Function EndTimer() EndTimer = apiGetTime() - lngStartTime End Function Sub StartTimer() lngStartTime = apiGetTime() End Sub '*-Class function / sub declaration This class allows me to create instances on demand to time things. One of the things I timed awhile back is how long it takes to do a bunch of different vb code things. For example: How long to call a function, passing no parameters. How long to call a function passing a parameter. How long to call a function returning a value from the function. How long to do a left$() Etc. A couple of examples of these tests follow: Function TestLeftStr() Dim lclsTimer As clsTimer Dim lngCnt As Long Dim str As String Set lclsTimer = New clsTimer lclsTimer.StartTimer For lngCnt = 1 To 100000 str = Left$("johncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohnco lbyjohncolby", 10) Next lngCnt Debug.Print lclsTimer.EndTimer End Function Function RetStr() As String RetStr = "johncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjoh ncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncol byjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolbyjohncolby" End Function Function PassStr() End Function Function TestPassParam() Dim lclsTimer As clsTimer Dim lngCnt As Long Dim str As String Dim str2 As String Set lclsTimer = New clsTimer str = "johncolby" str2 = "marycolby" lclsTimer.StartTimer For lngCnt = 1 To 100000 PassStr Next lngCnt Debug.Print lclsTimer.EndTimer End Function Function TestRetParam() Dim lclsTimer As clsTimer Dim lngCnt As Long Dim str As String Set lclsTimer = New clsTimer lclsTimer.StartTimer For lngCnt = 1 To 100000 str = RetStr() Next lngCnt Debug.Print lclsTimer.EndTimer End Function Etc. Etc. I thought for my first article I would build up a little database where we (as a group) could request timings of specific functionality that we are interested in seeing run. I will be building a table and adding code to store the timing results to the table. Anyone interested in having something timed and showing the results to the group can email me working code and I will include it in the project. As you can see you can do your own timing on your own systems, however if you want to compare apples to apples the timing has to be done on a single system. I will place the code in modules and run the timings, storing the results to a table and upload the database to the new dba website where my article will be posted. The timing class is just the beginning of course. It is rather the perfect "introductory" class to demonstrate encapsulation of data and functionality, instancing etc. I use this class all the time to time execution of queries, code etc. Anyway, if you would like to see some thing timed and included in a database of "how long it takes to..." get me working code (not TOO complex please) and I will put it in the demo database with the code executed (timed) and the timings stored in a table. Also think about what you could contribute to the web site. Thanks, John W. Colby www.ColbyConsulting.com Contribute your unused CPU cycles to a good cause: http://folding.stanford.edu/ -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com