Implementation of ASP program execution time statistics class code _asp class

Source: Internet
Author: User
Tags square root
The first time to write ASP class, to achieve the function: the implementation of a phased statistical program, output statistics and so on.
Copy Code code as follows:

Class Ccclsprocesstimerecorder
' Program Author: Moon Starlight
' Author homepage: Http://www.5iya.com/blog
' Http://www.kuozhanming.com
' ASP program code execution time Statistics class

Private Ccinti,ccintnoncetime,ccintdecimal
Private ccintstarttime,ccintendtime,ccintnow,ccintnonce
Private Ccstrinterval,ccstrevent,ccstrtime,ccstrstatisticlog,ccstrformatinterval
Private Ccarrevent,ccarrtime

Private Sub Class_Initialize
Ccstrinterval = "|" ' Default separator
Ccintdecimal = 4 ' digits after decimal point
Ccstrevent = ""
Ccstrtime = ""
Ccstrformatinterval = "<br/>" & vbCrLf
Ccintstarttime = Timer
Ccintnow = Ccintstarttime
Ccintnonce = Ccintstarttime
End Sub

Public Sub record (ccstreventname)
Ccstrevent = ccstrevent & Ccstrinterval & Replace (Ccstreventname,ccstrinterval, "")
Ccstrtime = ccstrtime & Ccstrinterval & FormatNumber (timer-ccintnow,ccintdecimal,true,false,true)
Ccintnow = Timer
End Sub

Public Property Let Format (Ccstrformattype)
If LCase (Trim (ccstrformattype)) = "html" Then
Ccstrformatinterval = "<br/>" & vbCrLf
Else
Ccstrformatinterval = VbCrLf
End If
End Property

Public Function Statistic
If InStr (Ccstrevent,ccstrinterval) > 0 Then
Ccintendtime = Timer
Ccarrevent = Split (ccstrevent,ccstrinterval)
Ccarrtime = Split (ccstrtime,ccstrinterval)
Ccstrstatisticlog = Ccstrstatisticlog & "Process time record" & Ccstrformatinterval
Ccstrstatisticlog = ccstrstatisticlog & "--------------------------------------" & Ccstrformatinterval
For ccinti = 1 to UBound (ccarrevent)
Ccstrstatisticlog = Ccstrstatisticlog & Ccarrevent (Ccinti) & ":" & Ccarrtime (Ccinti) & "s" & CCSTRF Ormatinterval
Next
Ccstrstatisticlog = ccstrstatisticlog & "--------------------------------------" & Ccstrformatinterval
Ccstrstatisticlog = ccstrstatisticlog & "total:" & FormatNumber (Ccintendtime-ccintstarttime,ccintdecimal, True,false,true) & "s"
Statistic = Ccstrstatisticlog
Else
statistic = "No record"
End If
End Function

Public Function Nonce
Ccintnoncetime = FormatNumber (timer-ccintnonce,ccintdecimal,true,false,true)
Ccintnonce = Timer
Nonce = Ccintnoncetime
End Function

Public Function Total
Total = FormatNumber (timer-ccintstarttime,ccintdecimal,true,false,true)
End Function

End Class


Class Properties:
1.Format
Output with HTML wrapping label
-html: Output HTML newline label and text line break (default)
-text: Output text line breaks only

Class method:
1.Record ("Code Name")
Counts the time since the last call to the record method to the present (the first call when the statistic Declaration class is at the time of the call), and finally the output in the statistic

Class functions: (Instant return information)
1.Nonce
The output from the last call to the Nonce function to the current time (the first call when the statistics declaration class up to the call time)
2.Total
Output declaration class up to now total time
3.Statistic
Output all record statistics and total program time

Instance code:
Copy Code code as follows:

Dim objrecord,i,k,j,x

Set objrecord = New Ccclsprocesstimerecorder
Objrecord.format = "html"

For i = 1 to 100000
x = 2 + 2
Next

Call Objrecord.record ("addition")
For j = 1 to 100000
x = 2 * 2
Next

Call Objrecord.record ("multiplication")

For k = 1 to 100000
x = 2 ^ 2
Next

Call Objrecord.record ("square root")

Response.Write objrecord.statistic



Output:
Process Time Record
--------------------------------------
Addition: 0.0625 s
Multiplication: 0.0469 s
Radical: 0.1094 S
--------------------------------------
total:0.2188 s
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.