手机
当前位置:查字典教程网 >编程开发 >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模板类代码

ASP程序密码验证漏洞解决方案

Utf-8和Gb2312乱码问题的终结

简单的ASP中经常用到的代码[推荐]第1/4页

ASP编程常用的代码

ASP常用函数收藏乱七八糟未整理版

ASP通用模板类

ASP抽取数据的执行效率

新型ASP后门源代码分析

用ASP+DLL实现WEB方式修改服务器时间

精品推荐
分类导航