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! | Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
| | | | You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
| | | | Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications. FREE! Go There Now!
| | | | Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
| | | | IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects. FREE! Go There Now!
| | | | Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available. FREE! Go There Now!
| | | | Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started. FREE! Go There Now!
| | | | Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
| | | | Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable. FREE! Go There Now!
| | | | With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |