Implementation functions: segmented statistics of program execution time, output of statistical tables, etc.
Class source code:
program code
Class ccClsProcessTimeRecorder
'Program author: Mingyue Xingguang
'Author's 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 'Number of 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 to include HTML line break tags when outputting
-html: Output HTML newline tags and text newlines (default)
-text: Only output text newline
class method:
1.Record("Code Name")
Count the time since the last call to the Record method to the present (the first call counts the time from when the class was declared to the time when it was called), and finally output
the class function in Statistics: (immediate return information)
1.Nonce
Output the time since the last time the nonce function was called to the present (the time from when the class was declared for the first time to when it was called is counted)
2.Total
Output the total time to declare the class until now
3.Statistic
Example code
to output all Record statistics and total program time
:
program code
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
Square root: 0.1094 s
-----------------------------------------------
Total: 0.2188 s