ASP程序代码执行时间统计类
作者:cloudream 来源:随想飞翔 发布时间:2007-10-15 12:45:00
标签:类,统计,时间
第一次写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
0
投稿
猜你喜欢
- 有这样一个要求,它要创建一个SQL Server查询,其中包括基于事件时刻的累计值。典型的例子就是一个银行账户,因为你每一次都是在不同的时间
- 从毕业实习算起,从事可用性方面的工作到现在已经5年了。在此记录笔者的一些所见所想,和大家讨论分享一下。用户研究在“以用户为中心”的界面设计方
- 如何做一个看他爱不爱你的小测验?<%CurQ = Request.Form("CurQ")An
- 根据google最新的算法规则:用户行为模式的重视程度越来越高,这也就要求网页设计的时候应注意“合理的网页结构”,SEO业界也有个共识“网页
- Dreamweaver从出道以来,其简便易用而又功能强大的“行为”(Behavior)一直是大家所关注的热点之一。在Dreamweaver
- 我们在设计网站的时候,有的时候需要根据页面元素的属性来制作不同的样式,比如,对于不同的链接类型,显示不同的链接图标。CSS的选择器是个很有用
- 代码如下: <!-- #include file="../conn.asp" --> <!-- #in
- 大家都用过企业管理器中的--“收缩数据库”,里面的功能的确可以收缩数据库的日志文件(.ldf)和数据文件(.mdf),但都会发现同样的问题,
- 可试试下面这个方法,但要保证在FORM中使用的Input Name都和数据库中使用的是一样的:upfiles.asp<% &
- 段落已经讲完了,那么一些基本的应用方式也讲了一些,那么是否已经应用了呢?当然应用可以更为丰富,那么这些就需要自己在实际工作中不断的摸索与思考
- <% Function FileCounter(counter_file) Dim fs,txt,fi
- 用下面代码可实现:<%Dim writeDim fileSysObj, tf, readrea
- SELECT表名=case when a.colorder=1 then d.name else '' end,表说明=ca
- 当我们使用一个数据库时,总希望数据库的内容是可靠的、正确的,但由于计算机系统的故障(包括机器故障、介质故障、误操作等),数据库有时也可能遭到
- 生成静态页的方法有很多种,我比较喜欢用xmlhttp的方法生成,因为我不用考虑很多东西,我只要把动态的asp页面编写好就行了。<% s
- 原文地址:30 Days of Mootools 1.2 Tutorials - Day 5 - Event HandlingMooTool
- System.Data.OleDb.OleDbDataAdapter与System.Data.OleDb.OleDbDataReader的区
- 今天工作中遇到,拿出来说说。网上CSS下拉菜单不少,不过都存在这样那样的问题,主要问题是,如果你菜单下面有一个FLASH的话,很多都会被FL
- 防止Application对象在多线程访问中出现错误asp代码处理代码如下(VB):<%Application.Lock()Appli
- 当您使用FILESYSTEMOBJECT(fso)对象获得某个目录下的文件列表的时候,你有没有发现无法控制它们的排序方式,比如按照名字排序,