Timing ASP Scripts



Click here for a larger image.

Environment: ASP .NET, ASP

Introduction

This article describes a simple function that gets the duration time call of your ASP scripts. It's very useful to find the time elapsed between two points in your ASP scripts (for example, a DB calls script).

How to Use the Program

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 time counter with this line:

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

Your ASP time-evaluated code must be between these two calls:

  'here 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 this code:

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

Downloads

Download demo project - 1 Kb


Comments

  • ok

    Posted by mayursolanki_007 on 08/03/2006 08:42am

    ok

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Is your sales and operations planning helping or hurting your bottom line? Here are 5 useful tips from the experts at Quintiq to guide you to a better S&OP strategy.

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today make data protection a must-have, as we live in a data driven society. The digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join eVault Chief Technology …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds