Most accurate timing in VB .NET??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Howard Kaikow

    Most accurate timing in VB .NET??

    In VB, I've developed the habit of using the API QueryPerformanc eCounter to
    achieve the most accurate timings.

    In VB .NET, one can use TotalMillisecon ds and Ticks to convert time to
    milliseconds.
    Is this as accurate as using the QueryPerformanc eCounter?

    What is the resolution of Now in VB .NET?

    For example:

    Dim datEnd As Date
    Dim datStart As Date

    datStart = Now
    ' Do stuff here
    datEnd = Now
    MsgBox((datEnd. Ticks - datStart.Ticks) / 10000 & " milliseconds(Ti cks)" &
    vbCrLf & _
    datEnd.Subtract (datStart).Tota lMilliseconds.T oString() & "
    milliseconds(Su btract)")

    --
    http://www.standards.com/; See Howard Kaikow's web site.


  • Ken Tucker [MVP]

    #2
    Re: Most accurate timing in VB .NET??

    Hi,

    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


    Ken
    --------------
    "Howard Kaikow" <kaikow@standar ds.com> wrote in message
    news:uM3R5l4LEH A.128@TK2MSFTNG P09.phx.gbl...[color=blue]
    > In VB, I've developed the habit of using the API QueryPerformanc eCounter
    > to
    > achieve the most accurate timings.
    >
    > In VB .NET, one can use TotalMillisecon ds and Ticks to convert time to
    > milliseconds.
    > Is this as accurate as using the QueryPerformanc eCounter?
    >
    > What is the resolution of Now in VB .NET?
    >
    > For example:
    >
    > Dim datEnd As Date
    > Dim datStart As Date
    >
    > datStart = Now
    > ' Do stuff here
    > datEnd = Now
    > MsgBox((datEnd. Ticks - datStart.Ticks) / 10000 & " milliseconds(Ti cks)" &
    > vbCrLf & _
    > datEnd.Subtract (datStart).Tota lMilliseconds.T oString() & "
    > milliseconds(Su btract)")
    >
    > --
    > http://www.standards.com/; See Howard Kaikow's web site.
    >
    >[/color]


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Most accurate timing in VB .NET??

      Howard,
      I normally use QueryPerformanc eCounter as I understand it has a sub
      millisecond resolution. Plus it is the resolution of the PerformanceCoun ter
      classes.

      When Whidbey (VS.NET 2005) arrives we will have System.Diagnost ics.Stopwatch
      class that you can use as a high resolution timer. I understand that it will
      decides which is better (higher resolution) DateTime.Ticks or
      QueryPerformanc eCount.




      Remember the QueryPerformanc eFrequency function indicates what the
      resolution of the QueryPerformanc eCounter function is. Ticks are at a fixed
      resolution of 100-nanosecond, however I understand they may not be updated
      every 100-nanoseconds...

      Hope this helps
      Jay

      "Howard Kaikow" <kaikow@standar ds.com> wrote in message
      news:uM3R5l4LEH A.128@TK2MSFTNG P09.phx.gbl...[color=blue]
      > In VB, I've developed the habit of using the API QueryPerformanc eCounter[/color]
      to[color=blue]
      > achieve the most accurate timings.
      >
      > In VB .NET, one can use TotalMillisecon ds and Ticks to convert time to
      > milliseconds.
      > Is this as accurate as using the QueryPerformanc eCounter?
      >
      > What is the resolution of Now in VB .NET?
      >
      > For example:
      >
      > Dim datEnd As Date
      > Dim datStart As Date
      >
      > datStart = Now
      > ' Do stuff here
      > datEnd = Now
      > MsgBox((datEnd. Ticks - datStart.Ticks) / 10000 & " milliseconds(Ti cks)" &
      > vbCrLf & _
      > datEnd.Subtract (datStart).Tota lMilliseconds.T oString() & "
      > milliseconds(Su btract)")
      >
      > --
      > http://www.standards.com/; See Howard Kaikow's web site.
      >
      >[/color]


      Comment

      • Armin Zingler

        #4
        Re: Most accurate timing in VB .NET??

        "Howard Kaikow" <kaikow@standar ds.com> schrieb[color=blue]
        > In VB, I've developed the habit of using the API
        > QueryPerformanc eCounter to achieve the most accurate timings.
        >
        > In VB .NET, one can use TotalMillisecon ds and Ticks to convert time
        > to milliseconds.
        > Is this as accurate as using the QueryPerformanc eCounter?
        >
        > What is the resolution of Now in VB .NET?
        >
        > For example:
        >
        > Dim datEnd As Date
        > Dim datStart As Date
        >
        > datStart = Now
        > ' Do stuff here
        > datEnd = Now
        > MsgBox((datEnd. Ticks - datStart.Ticks) / 10000 & "
        > milliseconds(Ti cks)" & vbCrLf & _
        > datEnd.Subtract (datStart).Tota lMilliseconds.T oString() & "
        > milliseconds(Su btract)")[/color]





        --
        Armin

        How to quote and why:



        Comment

        • Cor Ligthert

          #5
          Re: Most accurate timing in VB .NET??

          Hi Howard,

          I really do not know if it is accurate, however there is also an
          enviroment.tick count which comes from the system timer

          The problem is in my idea not the precise part, however in which way your
          process has access to those timers continuly.

          Maybe you can try that yourself.



          Cor


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Most accurate timing in VB .NET??

            * "Howard Kaikow" <kaikow@standar ds.com> scripsit:[color=blue]
            > In VB .NET, one can use TotalMillisecon ds and Ticks to convert time to
            > milliseconds.
            > Is this as accurate as using the QueryPerformanc eCounter?[/color]

            It isn't. I would still use 'QueryPerforman ceCounter', for example:

            <URL:http://www.mentalis.or g/soft/class.qpx?id=8>

            --
            Herfried K. Wagner [MVP]
            <URL:http://dotnet.mvps.org/>

            Comment

            • Howard Kaikow

              #7
              Re: Most accurate timing in VB .NET??

              Thanx fer the responses.
              I'll stick with the QueryPerformanc eCounter.

              --
              http://www.standards.com/; See Howard Kaikow's web site.
              "Howard Kaikow" <kaikow@standar ds.com> wrote in message
              news:uM3R5l4LEH A.128@TK2MSFTNG P09.phx.gbl...[color=blue]
              > In VB, I've developed the habit of using the API QueryPerformanc eCounter[/color]
              to[color=blue]
              > achieve the most accurate timings.
              >
              > In VB .NET, one can use TotalMillisecon ds and Ticks to convert time to
              > milliseconds.
              > Is this as accurate as using the QueryPerformanc eCounter?
              >
              > What is the resolution of Now in VB .NET?
              >
              > For example:
              >
              > Dim datEnd As Date
              > Dim datStart As Date
              >
              > datStart = Now
              > ' Do stuff here
              > datEnd = Now
              > MsgBox((datEnd. Ticks - datStart.Ticks) / 10000 & " milliseconds(Ti cks)" &
              > vbCrLf & _
              > datEnd.Subtract (datStart).Tota lMilliseconds.T oString() & "
              > milliseconds(Su btract)")
              >
              > --
              > http://www.standards.com/; See Howard Kaikow's web site.
              >
              >[/color]


              Comment

              • Howard Kaikow

                #8
                Re: Most accurate timing in VB .NET??

                Thanx fer the responses.
                I'll stick with the QueryPerformanc eCounter.

                --
                http://www.standards.com/; See Howard Kaikow's web site.
                "Howard Kaikow" <kaikow@standar ds.com> wrote in message
                news:uM3R5l4LEH A.128@TK2MSFTNG P09.phx.gbl...[color=blue]
                > In VB, I've developed the habit of using the API QueryPerformanc eCounter[/color]
                to[color=blue]
                > achieve the most accurate timings.
                >
                > In VB .NET, one can use TotalMillisecon ds and Ticks to convert time to
                > milliseconds.
                > Is this as accurate as using the QueryPerformanc eCounter?
                >
                > What is the resolution of Now in VB .NET?
                >
                > For example:
                >
                > Dim datEnd As Date
                > Dim datStart As Date
                >
                > datStart = Now
                > ' Do stuff here
                > datEnd = Now
                > MsgBox((datEnd. Ticks - datStart.Ticks) / 10000 & " milliseconds(Ti cks)" &
                > vbCrLf & _
                > datEnd.Subtract (datStart).Tota lMilliseconds.T oString() & "
                > milliseconds(Su btract)")
                >
                > --
                > http://www.standards.com/; See Howard Kaikow's web site.
                >
                >[/color]


                Comment

                • Howard Kaikow

                  #9
                  Re: Most accurate timing in VB .NET??

                  "Armin Zingler" <az.nospam@free net.de> wrote in message
                  news:4093bed4$2 $27042$9b622d9e @news.freenet.d e...[color=blue]
                  > "Howard Kaikow" <kaikow@standar ds.com> schrieb[color=green]
                  > > In VB, I've developed the habit of using the API
                  > > QueryPerformanc eCounter to achieve the most accurate timings.
                  > >
                  > > In VB .NET, one can use TotalMillisecon ds and Ticks to convert time
                  > > to milliseconds.
                  > > Is this as accurate as using the QueryPerformanc eCounter?
                  > >
                  > > What is the resolution of Now in VB .NET?
                  > >
                  > > For example:
                  > >
                  > > Dim datEnd As Date
                  > > Dim datStart As Date
                  > >
                  > > datStart = Now
                  > > ' Do stuff here
                  > > datEnd = Now
                  > > MsgBox((datEnd. Ticks - datStart.Ticks) / 10000 & "
                  > > milliseconds(Ti cks)" & vbCrLf & _
                  > > datEnd.Subtract (datStart).Tota lMilliseconds.T oString() & "
                  > > milliseconds(Su btract)")[/color]
                  >
                  >
                  >[/color]


                  The article uses

                  Win32.QueryPerf ormanceCounter( Counter)

                  Is there a .NET library that imports the API?
                  Where is the Win32 object defined?


                  Comment

                  • Howard Kaikow

                    #10
                    Re: Most accurate timing in VB .NET??

                    "Armin Zingler" <az.nospam@free net.de> wrote in message
                    news:4093bed4$2 $27042$9b622d9e @news.freenet.d e...[color=blue]
                    > "Howard Kaikow" <kaikow@standar ds.com> schrieb[color=green]
                    > > In VB, I've developed the habit of using the API
                    > > QueryPerformanc eCounter to achieve the most accurate timings.
                    > >
                    > > In VB .NET, one can use TotalMillisecon ds and Ticks to convert time
                    > > to milliseconds.
                    > > Is this as accurate as using the QueryPerformanc eCounter?
                    > >
                    > > What is the resolution of Now in VB .NET?
                    > >
                    > > For example:
                    > >
                    > > Dim datEnd As Date
                    > > Dim datStart As Date
                    > >
                    > > datStart = Now
                    > > ' Do stuff here
                    > > datEnd = Now
                    > > MsgBox((datEnd. Ticks - datStart.Ticks) / 10000 & "
                    > > milliseconds(Ti cks)" & vbCrLf & _
                    > > datEnd.Subtract (datStart).Tota lMilliseconds.T oString() & "
                    > > milliseconds(Su btract)")[/color]
                    >
                    >
                    >[/color]


                    The article uses

                    Win32.QueryPerf ormanceCounter( Counter)

                    Is there a .NET library that imports the API?
                    Where is the Win32 object defined?


                    Comment

                    • Armin Zingler

                      #11
                      Re: Most accurate timing in VB .NET??


                      "Howard Kaikow" <kaikow@standar ds.com> schrieb im Newsbeitrag news:%> >[color=blue]
                      >[/color]
                      http://groups.google.com/groups?selm...TNGP10.phx.gbl[color=blue]
                      >
                      > The article uses
                      >
                      > Win32.QueryPerf ormanceCounter( Counter)
                      >
                      > Is there a .NET library that imports the API?
                      > Where is the Win32 object defined?[/color]


                      No, sorry, I forgot them:

                      public notinheritable class Win32
                      Public Declare Auto Function QueryPerformanc eCounter _
                      Lib "kernel32.d ll" (ByRef Counter As Long) As Integer
                      Public Declare Auto Function QueryPerformanc eFrequency _
                      Lib "kernel32.d ll" (ByRef counter As Long) As Integer

                      private sub new
                      end sub
                      end class




                      --
                      Armin

                      How to quote and why:



                      Comment

                      • Armin Zingler

                        #12
                        Re: Most accurate timing in VB .NET??


                        "Howard Kaikow" <kaikow@standar ds.com> schrieb im Newsbeitrag news:%> >[color=blue]
                        >[/color]
                        http://groups.google.com/groups?selm...TNGP10.phx.gbl[color=blue]
                        >
                        > The article uses
                        >
                        > Win32.QueryPerf ormanceCounter( Counter)
                        >
                        > Is there a .NET library that imports the API?
                        > Where is the Win32 object defined?[/color]


                        No, sorry, I forgot them:

                        public notinheritable class Win32
                        Public Declare Auto Function QueryPerformanc eCounter _
                        Lib "kernel32.d ll" (ByRef Counter As Long) As Integer
                        Public Declare Auto Function QueryPerformanc eFrequency _
                        Lib "kernel32.d ll" (ByRef counter As Long) As Integer

                        private sub new
                        end sub
                        end class




                        --
                        Armin

                        How to quote and why:



                        Comment

                        • Howard Kaikow

                          #13
                          Re: Most accurate timing in VB .NET??

                          Thanx.

                          --
                          http://www.standards.com/; See Howard Kaikow's web site.
                          "Armin Zingler" <az.nospam@free net.de> wrote in message
                          news:40950172$0 $12458$9b622d9e @news.freenet.d e...[color=blue]
                          >
                          > "Howard Kaikow" <kaikow@standar ds.com> schrieb im Newsbeitrag news:%> >[color=green]
                          > >[/color]
                          >[/color]
                          http://groups.google.com/groups?selm...TNGP10.phx.gbl[color=blue][color=green]
                          > >
                          > > The article uses
                          > >
                          > > Win32.QueryPerf ormanceCounter( Counter)
                          > >
                          > > Is there a .NET library that imports the API?
                          > > Where is the Win32 object defined?[/color]
                          >
                          >
                          > No, sorry, I forgot them:
                          >
                          > public notinheritable class Win32
                          > Public Declare Auto Function QueryPerformanc eCounter _
                          > Lib "kernel32.d ll" (ByRef Counter As Long) As Integer
                          > Public Declare Auto Function QueryPerformanc eFrequency _
                          > Lib "kernel32.d ll" (ByRef counter As Long) As Integer
                          >
                          > private sub new
                          > end sub
                          > end class
                          >
                          >
                          >
                          >
                          > --
                          > Armin
                          >
                          > How to quote and why:
                          > http://www.plig.net/nnq/nquote.html
                          > http://www.netmeister.org/news/learn2quote.html
                          >[/color]


                          Comment

                          • Howard Kaikow

                            #14
                            Re: Most accurate timing in VB .NET??

                            Thanx.

                            --
                            http://www.standards.com/; See Howard Kaikow's web site.
                            "Armin Zingler" <az.nospam@free net.de> wrote in message
                            news:40950172$0 $12458$9b622d9e @news.freenet.d e...[color=blue]
                            >
                            > "Howard Kaikow" <kaikow@standar ds.com> schrieb im Newsbeitrag news:%> >[color=green]
                            > >[/color]
                            >[/color]
                            http://groups.google.com/groups?selm...TNGP10.phx.gbl[color=blue][color=green]
                            > >
                            > > The article uses
                            > >
                            > > Win32.QueryPerf ormanceCounter( Counter)
                            > >
                            > > Is there a .NET library that imports the API?
                            > > Where is the Win32 object defined?[/color]
                            >
                            >
                            > No, sorry, I forgot them:
                            >
                            > public notinheritable class Win32
                            > Public Declare Auto Function QueryPerformanc eCounter _
                            > Lib "kernel32.d ll" (ByRef Counter As Long) As Integer
                            > Public Declare Auto Function QueryPerformanc eFrequency _
                            > Lib "kernel32.d ll" (ByRef counter As Long) As Integer
                            >
                            > private sub new
                            > end sub
                            > end class
                            >
                            >
                            >
                            >
                            > --
                            > Armin
                            >
                            > How to quote and why:
                            > http://www.plig.net/nnq/nquote.html
                            > http://www.netmeister.org/news/learn2quote.html
                            >[/color]


                            Comment

                            Working...