Timing and Benchmarking ASP Scripts by Robert Chartier

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
May 03, 2001
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement
The simplest way to time a script is to basically take a snapshot (now())of the current time before some processing, and then take a snapshot at the end of the processing. For example:
0. <%
1. Dim dtBefore, dtAfter
2. dtBefore = now()
3. For x = 0 to 1000
4. a = a + 1000
5. next
6. dtAfter = now()
7.
8. response.write "Duration (seconds)"& dateDiff("s",dtAfter,dtBefore)
9.
10. %>


What we would like to do is get access to a more finer scale of measurement. We can easily do this via COM. Below is the source for a class file that I threw together that uses the API call GetTickCount().

Timer.cls Code Output
0. 'GetTickCount Declaration
1. Private Declare Function GetTickCount Lib "Kernel32" () As Long
2. 'The GetTickCount function retrieves the number of
3. 'milliseconds that have elapsed since the system was started.
4. 'It is limited to the resolution of the system timer.
5. 'http://msdn.microsoft.com/library/psdk/sysmgmt/time_8wz8.htm
6.
7.
8. Dim aNames(50) As String
9. Dim aTimes(50) As Long
10. Dim maxTimes As Long
11. Dim allNames As String
12.
13. Public Sub setTime(ByVal name As String)
14. If InStr(allNames, name + ",") > 0 Then
15. For x = 0 To maxTimes
16. If aNames(x) = name Then
17. aTimes(x) = GetTickCount()
18. Exit For
19. End If
20. Next
21. Else
22. maxTimes = maxTimes + 1
23. aNames(maxTimes) = name
24. aTimes(maxTimes) = GetTickCount()
25. allNames = allNames + name + ","
26. End If
27. End Sub
28.
29. Public Function getTime(ByVal name As String) As Long
30. If InStr(allNames, name) > 0 Then
31. For x = 0 To maxTimes
32. If aNames(x) = name Then
33. getTime = aTimes(x)
34. Exit For
35. End If
36. Next
37. Else
38. getTime = 0
39. End If
40. End Function
41.
42. Public Function getNow() As Long
43. getNow = GetTickCount()
44. End Function
45.
46. Public Function formatTime(ByVal lTime1 As Long) As String
47. 'parts borrowed from MSDN
48.
49. Dim hour As Integer, minute As Integer, second As Integer
50. Dim raw
51. raw = lTime1 \ 1000
52. hour = raw \ 3600
53. raw = raw - (hour * 3600)
54. minute = raw \ 60
55. raw = raw - (minute * 60)
56. second = raw
57. If minute < 10 Then
58. If second < 10 Then
59. sReturn = hour & ":0" & minute & ":0" & second
60. Else
61. sReturn = hour & ":0" & minute & ":" & second
62. End If
63. Else
64. If second < 10 Then
65. sReturn = hour & ":" & minute & ":0" & second
66. Else
67. sReturn = hour & ":" & minute & ":" & second
68. End If
69. End If
70. formatTime = sReturn
71. End Function

Download Full Source here and compile the DLL on your machine (see references section). (you can also use the DLL that I have compiled on my machine -windows 2000-). Once you have the DLL, register it on your machine, either using "regsvr32 dllpath\dllname.dll" or use Component Services/MTS (for more information).

Copy Source:
blog comments powered by Disqus
DATABASE CODE ARTICLES

- Deployment of the MobiLink Synchronization M...
- MobiLink Synchronization Wizard in SQL Anywh...
- Finding Matching Records in Data Access Pages
- Using the AccessDataSource Control in VS 2005
- A Closer Look at ADO.NET: The Command Object
- A Closer Look at ADO.NET: The Connection Obj...
- Using ADO to Communicate with the Database, ...
- Code Snippets: Counting Records
- Constraints In Microsoft SQL Server 2000
- Multilingual entries into a DB and to be dis...
- Two combos, one textbox example
- ADO Recordset Paging
- SQL Server Database Creator - .NET Version
- Getting A List of Tables From SQL Server
- Discussion & Listserv Module by Mike Eck...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials