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

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 23, 2014 @ 12:00 p.m. ET / 9:00 a.m. PT Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this eSeminar to learn why physical appliances are preferable to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds