|
-
Mar 12th, 2002, 10:26 AM
#1
Thread Starter
Hyperactive Member
TimeGetTime
In the past when trying to monitor performance I have always used the "TimeGetTime" api,
However with vb.Net I noticed that the "timespan" object can be displayed in ticks or total seconds so I experimented with something like following code.
VB Code:
dim datStart as Date
dim datEnd as Date
dim timSpan as TimeSpan
dim strDisplayTime as String
datStart = now
... 'code to be timed
datEnd = now
timSpan = datEnd.Subtract(datStart)
strDisplayTime = timSpan.ToString 'hh:mm:ss.mmmmm
strDisplayTime = timSpan.Ticks.ToString 'tttttttttt
strDisplayTime = timSpan.TotalSeconds.ToString 's.mmmmmm
My problem is that although on the whole this works if the code to be timed was very small, ie intX = 0 then the Start and End Times are indentical. I assume this is because the Date function only records time down to x number of decimal places and so not enough time has passed.
Should I be using something other that a "date" variable and setting it to now. Ideally I would like to use soemthing from within the .Net framework, and not an api call.
Thanks for any help
-
Mar 12th, 2002, 02:22 PM
#2
perhaps record the system tick count
start = System.Environment.TickCount
???????
I would guess it is in ms and there should be some formatting for ms to seconds..not sure what it is in .NET yet.
-
Mar 13th, 2002, 06:37 AM
#3
Thread Starter
Hyperactive Member
Thanks for replying Cander.
I had a look at that - and it gave back the same results, ie it appears setting an int32 to 0 takes no time (or ticks). To be honest most of what I will be timing will be sql statements anyway - so what I have should be accurate enough.
Looking at it a different way this could of course just prove that .net is just infinitely fast - which can only be good news.
I did also look at datetime.ticks - but I assume that as this is from datetime - it would give the same results as my first test.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|