5,443,978 members and growing! (21,798 online)
Email Password   helpLost your password?
Web Development » ASP » General     Intermediate

Elapsed Time Script

By Adrian Bacaianu

This article describes a simple function which calculates the execution time of your asp scripts
Win2K, WinXP, Windows, ASP, Dev

Posted: 1 Jul 2002
Updated: 1 Jul 2002
Views: 45,700
Bookmarked: 21 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 3.29 Rating: 4.23 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
3 votes, 100.0%
5


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:

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	

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

About the Author

Adrian Bacaianu


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@yahoo.com).
Occupation: Web Developer
Location: Romania Romania

Other popular ASP articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 6 of 6 (Total in Forum: 6) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralSimple solutionmembermorphias23:34 16 Jul '05  
GeneralAnother alternativememberAnonymous6:14 5 Jul '02  
GeneralAlternativeadminChris Maunder0:08 2 Jul '02  
GeneralRe: AlternativememberAdrian Bacaianu4:36 2 Jul '02  
GeneralRe: Alternativememberjvnk113:22 1 Mar '06  
GeneralRe: Alternativememberjvnk113:22 1 Mar '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 1 Jul 2002
Editor: James Spibey
Copyright 2002 by Adrian Bacaianu
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project