Click here to Skip to main content
15,881,380 members
Articles / Programming Languages / ASP
Article

Elapsed Time Script

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
1 Jul 2002 78.8K   540   28   6
This article describes a simple function which calculates the execution time of your asp scripts

Image 1

Description

This article describes a simple function which calculates the execution time for your asp scripts.
It's very useful to find the time elapsed between two points in your asp scripts (for example in scripts with DB calls).

How to use

First, you must include the following JavaScript functions in your asp script:

VBScript
function y2k(number)   
{
   return (number < 1000) ? number + 1900 : number;
}
function milliDif()   
{
   var d = new Date();
      return d.getTime()
}
                  
function elapsedpretty(parm1)
{
  var elapsedsecs = 0
  var elapsedmins = 0
  
  elapsedsecs=Math.floor(parm1/1000)
  parm1=parm1%1000
  
  elapsedmins=Math.floor(elapsedsecs/60)
  elapsedsecs=elapsedsecs%60
  
  elapsedpretty=elapsedmins + " minute"
  if(elapsedmins!=1)
       elapsedpretty=elapsedpretty+"s"
  
  elapsedpretty = elapsedpretty+" " + elapsedsecs+" second"
  if(elapsedsecs!=1)
       elapsedpretty=elapsedpretty+"s"
  
  elapsedpretty = elapsedpretty+ " "+parm1+" millisecond"
  if(parm1!=1)
       elapsedpretty=elapsedpretty+"s"
  
  return elapsedpretty;
}

After that, just start your timer with the following line:

VBScript
'[start section to be evaluated]
timeThen = milliDif()	

Between the two calls must be your asp time evaluated code.

VBScript
'here's some time consuming script code (like db calls for example)
for i=1 to 2000000
    i = i+1
next	

And finish the time counter with the following code:

VBScript
'[end section to be evaluated]
timeNow = milliDif()
elapsed = timeNow - timeThen
msg = "Process time in ms: " & elapsed &  elapsedpretty(elapsed)
response.write msg	

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Romania Romania
I make programming for over 4 years and extensive experience in C++, ASP, Pascal, MFC, COM+, ATL, TCP/IP, HTTP protocols, XML, XSL, SOAP and SQL.
For the last 2 years i working extensively at the background of financial sites (databases, n tier architecture).

I’m available for contracts and/or outsourcing (<Adrian Bacaianu>adrian_bacaianu@yahoo.com).

Comments and Discussions

 
GeneralSimple solution Pin
morphias16-Jul-05 22:34
morphias16-Jul-05 22:34 
GeneralAnother alternative Pin
5-Jul-02 5:14
suss5-Jul-02 5:14 
GeneralAlternative Pin
Chris Maunder1-Jul-02 23:08
cofounderChris Maunder1-Jul-02 23:08 
GeneralRe: Alternative Pin
Adrian Bacaianu2-Jul-02 3:36
Adrian Bacaianu2-Jul-02 3:36 
GeneralRe: Alternative Pin
jvnk111-Mar-06 2:22
jvnk111-Mar-06 2:22 
GeneralRe: Alternative Pin
jvnk111-Mar-06 2:22
jvnk111-Mar-06 2:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.