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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • According to a recent Forrester total economic impact (TEI) study, enterprises can see a significant reduction in total cost of ownership by accessing Oracle Database in the cloud with a pay-as-you-go subscription model. This subscription service gives businesses the ability to scale up application environments for rapid prototyping, with far less time devoted to procuring licenses and deploying IT infrastructure. Read this study to learn how three different companies use Oracle Database in the cloud and the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds