手机
当前位置:查字典教程网 >编程开发 >ASP教程 >实现ASP程序执行时间统计类的代码
实现ASP程序执行时间统计类的代码
摘要:第一次写ASP类,实现功能:分段统计程序执行时间,输出统计表等.复制代码代码如下:ClassccClsProcessTimeRecorder...

第一次写ASP类,实现功能:分段统计程序执行时间,输出统计表等.

复制代码 代码如下:

ClassccClsProcessTimeRecorder

'程序作者:明月星光

'作者主页:http://www.5iya.com/blog

'http://www.kuozhanming.com

'ASP程序代码执行时间统计类

PrivateccInti,ccIntNonceTime,ccIntDecimal

PrivateccIntStartTime,ccIntEndTime,ccIntNow,ccIntNonce

PrivateccStrInterval,ccStrEvent,ccStrTime,ccStrStatisticLog,ccStrFormatInterval

PrivateccArrEvent,ccArrTime

PrivateSubClass_Initialize

ccStrInterval="|"'默认分隔符

ccIntDecimal=4'小数点后位数

ccStrEvent=""

ccStrTime=""

ccStrFormatInterval="<br/>"&vbCrLf

ccIntStartTime=Timer

ccIntNow=ccIntStartTime

ccIntNonce=ccIntStartTime

EndSub

PublicSubRecord(ccStrEventName)

ccStrEvent=ccStrEvent&ccStrInterval&Replace(ccStrEventName,ccStrInterval,"")

ccStrTime=ccStrTime&ccStrInterval&FormatNumber(Timer-ccIntNow,ccIntDecimal,True,False,True)

ccIntNow=Timer

EndSub

PublicPropertyLetFormat(ccStrFormatType)

IfLCase(Trim(ccStrFormatType))="html"Then

ccStrFormatInterval="<br/>"&vbCrLf

Else

ccStrFormatInterval=vbCrLf

EndIf

EndProperty

PublicFunctionStatistic

IfInStr(ccStrEvent,ccStrInterval)>0Then

ccIntEndTime=Timer

ccArrEvent=Split(ccStrEvent,ccStrInterval)

ccArrTime=Split(ccStrTime,ccStrInterval)

ccStrStatisticLog=ccStrStatisticLog&"ProcessTimeRecord"&ccStrFormatInterval

ccStrStatisticLog=ccStrStatisticLog&"--------------------------------------"&ccStrFormatInterval

ForccInti=1ToUBound(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="NoRecord"

EndIf

EndFunction

PublicFunctionNonce

ccIntNonceTime=FormatNumber(Timer-ccIntNonce,ccIntDecimal,True,False,True)

ccIntNonce=Timer

Nonce=ccIntNonceTime

EndFunction

PublicFunctionTotal

Total=FormatNumber(Timer-ccIntStartTime,ccIntDecimal,True,False,True)

EndFunction

EndClass

类属性:

1.Format

输出时是否带HTML换行标签

-html:输出HTML换行标签和文本换行符(默认)

-text:仅输出文本换行符

类方法:

1.Record("CodeName")

统计自上一次调用Record方法至现在的时间(第一次调用时统计声明类时至调用时时间),最后在Statistic中输出

类函数:(即时返回信息)

1.Nonce

输出自上一次调用nonce函数至现在的时间(第一次调用时统计声明类时至调用时时间)

2.Total

输出声明类到现在总时间

3.Statistic

输出所有Record统计信息和总程序时间

实例代码:

复制代码 代码如下:

DimobjRecord,i,k,j,x

SetobjRecord=NewccClsProcessTimeRecorder

objRecord.Format="html"

Fori=1To100000

x=2+2

Next

CallobjRecord.Record("加法")

Forj=1To100000

x=2*2

Next

CallobjRecord.Record("乘法")

Fork=1To100000

x=2^2

Next

CallobjRecord.Record("开方")

Response.WriteobjRecord.Statistic

输出:

ProcessTimeRecord

--------------------------------------

加法:0.0625s

乘法:0.0469s

开方:0.1094s

--------------------------------------

Total:0.2188s

【实现ASP程序执行时间统计类的代码】相关文章:

用ASP实现对MP3曲目信息的操作

ASP + Serv-u 实现FTP的代码

ASP无组件分页实现思路及代码

统计有多少行JS代码和ASP代码

asp实现无限级分类的方法js版

纯编码实现Access数据库的建立或压缩

用asp实现的数据库中存取文件的代码

一段ASP 伪静态代码

asp 在线人数统计代码

asp实现表格3列5行

精品推荐
分类导航