当前位置: 移动技术网 > IT编程>开发语言>Asp > ASP程序代码执行时间统计类

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

2017年12月12日  | 移动技术网IT编程  | 我要评论
第一次写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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网