實現ASP程式執行時間統計類的代碼

來源:互聯網
上載者:User

第一次寫ASP類,實現功能:分段統計程式執行時間,輸出統計表等. 複製代碼 代碼如下:Class ccClsProcessTimeRecorder
'程式作者:明月星光
'作者首頁:http://www.5iya.com/blog
'http://www.kuozhanming.com
'ASP程式碼執行時間統計類

Private ccInti,ccIntNonceTime,ccIntDecimal
Private ccIntStartTime,ccIntEndTime,ccIntNow,ccIntNonce
Private ccStrInterval,ccStrEvent,ccStrTime,ccStrStatisticLog,ccStrFormatInterval
Private ccArrEvent,ccArrTime

Private Sub Class_Initialize
ccStrInterval = "|" '預設分隔符號
ccIntDecimal = 4 '小數點後位元
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

類屬性:
1.Format
輸出時是否帶HTML換列標籤
-html:輸出HTML換列標籤和文本分行符號(預設)
-text:僅輸出文本分行符號

類方法:
1.Record("Code Name")
統計自上一次調用Record方法至現在的時間(第一次調用時統計聲明類時至調用時時間),最後在Statistic中輸出

類函數:(即時返回資訊)
1.Nonce
輸出自上一次調用nonce函數至現在的時間(第一次調用時統計聲明類時至調用時時間)
2.Total
輸出聲明類到現在總時間
3.Statistic
輸出所有Record統計資訊和總程式時間

執行個體代碼: 複製代碼 代碼如下: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("加法")
For j = 1 To 100000
x = 2 * 2
Next

Call objRecord.Record("乘法")

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

Call objRecord.Record("開方")

Response.Write objRecord.Statistic

輸出:
Process Time Record
--------------------------------------
加法 : 0.0625 s
乘法 : 0.0469 s
開方 : 0.1094 s
--------------------------------------
Total : 0.2188 s

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.