Results 1 to 3 of 3

Thread: TimeGetTime

  1. #1

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

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

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    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
  •  



Click Here to Expand Forum to Full Width