Write ASP class for the first time to implement the function: Segment statistics program execution time, output statistics table, etc.
Copy codeThe Code is as follows: Class ccClsProcessTimeRecorder
'Author: Mingyue Xingguang
'Author Home: http://www.5iya.com/blog
'Http: // www.kuozhanming.com
'Asp program code execution time statistical 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 delimiter
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" & ccStrFormatInterval
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 attributes:
1. Format
Whether HTML line feed labels are included in the output
-Html: Output HTML line feed labels and text line breaks (default)
-Text: only text line breaks are output.
Class method:
1. Record ("Code Name ")
Count the time from the last time the Record method was called to the present time (the time when the Declaration class was called for the first time), and finally the output in Statistic
Class Functions: (immediate response)
1. Nonce
The time from the last call of the nonce function to the present (the time from the time when the declared class to the call is counted for the first call)
2. Total
Total time of output Declaration class till now
3. Statistic
Output all Record statistics and total program time
Instance code:Copy codeThe Code is as follows: Dim objRecord, I, k, j, x
Set objRecord = New ccClsProcessTimeRecorder
ObjRecord. Format = "html"
For 1 To 100000
X = 2 + 2
Next
Call objRecord. Record ("addition ")
For j = 1 ~ 100000
X = 2*2
Next
Call objRecord. Record ("multiplication ")
For k = 1 To 100000
X = 2 ^ 2
Next
Call objRecord. Record (" ")
Response. Write objRecord. Statistic
Output:
Process Time Record
--------------------------------------
Addition: 0.0625 s
Multiplication: 0.0469 s
Initiator: 0.1094 s
--------------------------------------
Total: 0.2188 s