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:
  1. dim datStart as Date
  2. dim datEnd as Date
  3. dim timSpan as TimeSpan
  4. dim strDisplayTime as String
  5.  
  6. datStart = now
  7. ... 'code to be timed
  8. datEnd = now
  9.  
  10. timSpan = datEnd.Subtract(datStart)
  11. strDisplayTime = timSpan.ToString 'hh:mm:ss.mmmmm
  12. strDisplayTime = timSpan.Ticks.ToString 'tttttttttt
  13. 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