CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Timer vs Time()

  1. #1
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Timer vs Time()

    Here is a Loop that uses Timer() to record how long a loop takes.
    A second Loop used Time() to track the same loop.
    The two loops record sisgnificantly different results.
    Anyone care to comment as to why and which is more accurate if either. I realize there is a Timer API I could be using but this is a curiosity.

    option Explicit
    '
    private Sub Command1_Click()
    Dim strt as Single, stp as Single, x as Long
    strt = time()
    Do Until x = 10000000
    x = x + 1
    Loop
    stp = time()
    print "time() " & stp - strt

    End Sub
    '
    private Sub Command2_Click()
    Dim strt as Single, stp as Single, x as Long
    strt = Timer
    Do Until x = 10000000
    x = x + 1
    Loop
    stp = Timer
    print "Timer " & stp - strt

    End Sub




    John G

  2. #2

    Re: Timer vs Time()

    try this for command1:

    Private Sub Command1_Click()
    Dim strt As Date, stp As Date, x As Long
    strt = Time()
    Do Until x = 10000000
    x = x + 1
    Loop
    stp = Time()
    Print "time() " & CDate(stp - strt)

    End Sub

    hi,brt

    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Timer vs Time()

    Thanks. It certainly brought the two answers closer together. Looking for something a little more resolution that seconds though.


    John G

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Timer vs Time()


    This may be related:
    gettickcount should be more accurated
    from apiguide:
    The GetTickCount function retrieves the number of milliseconds that have
    elapsed since Windows was started.
    'In general section
    private Declare Function GetTickCount& Lib "kernel32" ()
    private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    'get the tickcount
    ret& = GetTickCount&
    MsgBox Str$(ret& / 60000) + " minutes."
    End Sub




    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured