PDA

Click to See Complete Forum and Search --> : TimeGetTime


Bananafish
Mar 12th, 2002, 09:26 AM
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.



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

Cander
Mar 12th, 2002, 01:22 PM
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.

Bananafish
Mar 13th, 2002, 05:37 AM
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.