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: | DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Database Code Articles More By aspfree developerWorks - FREE Tools! | Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
| | | | Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools. FREE! Go There Now!
| | | | Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
| | | | Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle. FREE! Go There Now!
| | | | This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
| | | | Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions. FREE! Go There Now!
| | | | Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily. FREE! Go There Now!
| | | | Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |