Welcome to WebmasterWorld Guest from 3.92.92.168

Forum Moderators: ocean10000

Message Too Old, No Replies

ASP.NET Timer problem

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


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

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

Full Member

10+ Year Member

joined:Apr 27, 2003
posts:236
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 12, 2002
posts:1482
votes: 0


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

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


I'll try both solutions. Thanks guys!
4:20 pm on Jan 31, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Feb 19, 2004
posts:207
votes: 0


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))

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

Full Member

10+ Year Member

joined:Feb 19, 2004
posts:207
votes: 0


Sorry, I left out the Add method.

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

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 18, 2001
posts:1437
votes: 0


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.

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


Thanks! I'll try it.