![]() |
Web Development »
ASP »
General
Intermediate
Elapsed Time ScriptBy Adrian BacaianuThis article describes a simple function which calculates the execution time of your asp scripts |
Win2K, WinXP, ASP, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

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).
First, you must include the following JavaScript functions in your asp script:
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:
'[start section to be evaluated]
timeThen = milliDif()
Between the two calls must be your asp time evaluated code.
'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:
'[end section to be evaluated]
timeNow = milliDif()
elapsed = timeNow - timeThen
msg = "Process time in ms: " & elapsed & elapsedpretty(elapsed)
response.write msg
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 1 Jul 2002 Editor: James Spibey |
Copyright 2002 by Adrian Bacaianu Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |