Results 1 to 8 of 8

Thread: quickest way to measure the time in seconds and milliseconds

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    quickest way to measure the time in seconds and milliseconds

    Im wondering which is the best and quickest way to measure the time it takes for a block of code to execute? Are there any best practices????


    /Henrik

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    I would make 2 integers and use the TickCount.

    VB Code:
    1. Dim A,B as Integer
    2. A=Environment.TickCount
    3. 'Do code
    4. B=Environment.TickCount
    5.  
    6. Msgbox(B-A)

    This will show the time in milliseconds.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Does anyone really know how much effort it is in nunit to do that same thing? Perform unit testing of a function?

    /Henrik

  4. #4
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    N42 29.340 W71 53.215
    Posts
    422

    TickCount resolution 500 ms ?

    The online help for TickCount says
    The resolution of the TickCount property cannot be less than 500 milliseconds.
    Any idea what that means?

    BTW the same help mentions DateTime.Ticks, which sounds like a much better way to measure time, but I can't find it.

    DaveBo
    "The wise man doesn't know all the answers, but he knows where to find them."
    VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15

  5. #5
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Re: TickCount resolution 500 ms ?

    Originally posted by DaveBo
    The online help for TickCount says

    Any idea what that means?

    BTW the same help mentions DateTime.Ticks, which sounds like a much better way to measure time, but I can't find it.

    DaveBo
    Strange...I've had readings down to 50ms
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  6. #6
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    On my pc, the following code is about 75 ms when run the first time and 45 ms the rest of the times.

    This is with VS2003

    VB Code:
    1. Dim A, B, C As Integer
    2.         A = Environment.TickCount
    3.  
    4.         For C = 0 To 1000
    5.             Application.DoEvents()
    6.         Next
    7.  
    8.         B = Environment.TickCount
    9.  
    10.         MsgBox(B - A)
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    On my computor the following code gives a resolution of 2 milliseconds.

    VB Code:
    1. Dim d1, d2, d3 As Double
    2.         Dim icount As Integer
    3.         d1 = Environment.TickCount
    4.         Threading.Thread.Sleep(1000)
    5.  
    6.         d2 = Environment.TickCount
    7.  
    8.        d3 = d2-d1-1000

    So it looks like the MSDN article needs updating.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I believe that 500ms resolution is only in some really crappy cases. So it may or may not be the case.

    Here's a class used for timing during the prime numbers contest.

    http://www.mentalis.org/soft/class.qpx?id=8

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