Forum Moderators: open

Message Too Old, No Replies

ASP.NET Timer problem

         

nbozic

10:33 pm on Jan 30, 2005 (gmt 0)

10+ Year Member



Hi,

I'm trying to find out how long my script executes in asp.net (VB script).
I use this code on the top of the page:
StartTime = Timer

...and use this at the bottom of the page:
EndTime = Timer

The problem is that both of those numbers are exactly the same:
Something like "59297.15625", so I can't figure out how much time the webpage took to execute...

The numbers change when I refresh the page, but within the page all Timer values are the same.

Is it cached or something? How could I fix it?

Thanks,

NB

sharbel

5:14 am on Jan 31, 2005 (gmt 0)

10+ Year Member



Are you aware of ASP.NET's tracing ability? It's incredibly helpful at times, and shows a step by step 'timer' on the various events (page_init, pre-render, page load etc)

In your Page directive, just add trace="True" and you will see at the bottom of your page, all the load times, your control tree sizes etc.

mattglet

1:00 pm on Jan 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Of course they are the same, you're assigning both Start and End the same value.

Try something like this:

StartTime = Timer
Set Timer = Nothing

EndTime = Timer - StartTime

nbozic

2:52 pm on Jan 31, 2005 (gmt 0)

10+ Year Member



I'll try both solutions. Thanks guys!

raywood

4:20 pm on Jan 31, 2005 (gmt 0)

10+ Year Member



nbozic,
Here's the way I do it.

Right at the beginning of the script or routine:

Dim ElapsedTime As TimeSpan = New TimeSpan(0, 0, 0, 0, 0)
Dim start As Date
Dim finish As Date
start = TimeOfDay

Then at the end:
finish = TimeOfDay

Finally:
ElapsedTime = ElapsedTime(finish.Subtract(start))

raywood

4:23 pm on Jan 31, 2005 (gmt 0)

10+ Year Member



Sorry, I left out the Add method.

It should be:
ElapsedTime = ElapsedTime.Add(finish.Subtract(start))

nbozic

2:17 am on Feb 1, 2005 (gmt 0)

10+ Year Member



mattglet, I was unable to assign a value to the
Timer: "Set Timer = Nothing"
I got the error that "Timer" is readonly. Timer
is not something I created, It's something that
.net makes available, so I can't assign values
to it.

raywood, your solution looked so right... I was almost sure it would work, but for some reason it didn't.
Here is an example of what I got:

StartTime: 8:11:13 PM
---------- Some code that executes for a while...
EndTime: 8:11:13 PM
ElapsedTime: 00:00:00

No matter what, I always get an elapsed time of
"00:00:00".

I'm not sure what I'm doing wrong - maybe the time is cached on the server (while the same page executes).

Xoc

11:58 pm on Feb 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nope. The problem is that it is taking less than a second to generate the page, so it is rounding to zero.

Try displaying the .Ticks property of the time instead of formatting the time.

To use the Trace function (mentioned above), either 1) add the Trace="true" to the <%@Page> directive at the top of the aspx file (in HTML view) or 2) Add it to all pages on the site. Modify the web.config file and change the <trace enabled="false"> element to true. The use the virtual url [example.com...] where example.com is your domain name. You will then be able to look at the trace info for all recently visited pages.

nbozic

8:30 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



Thanks! I'll try it.