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