timeGetTime() vs Timer()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #1

    timeGetTime() vs Timer()

    If you're interested in measuring elapsed times in your Access Application, you're much better off using the timeGetTime() API Function instead of the Timer() VBA Function. There are 4 major reasons for this decision:
    __1. timeGetTime() is more accurate. The Timer() Function measure time in 'seconds' since Midnight in a single-precision floating-point value, and is not terribly accurate. timeGetTime() returns the number of 'milliseconds' that have elapsed since Windows has started and is very accurate.
    __2. timeGetTime() runs longer without 'rolling over'. Timer() rolls over every 24 hours. timeGetTime() keeps on ticking for up to 49 days before it resets the returned tick count to 0.
    __3. Calling timeGetTime() is significantly faster than calling Timer().
    __4. Calling timeGetTime() is no more complex than calling Timer(), once you've included the proper declaration as in:

    Code:
    Public Declare Function timeGetTime Lib "winmm.dll" () As Long
    A typical example of using timeGetTime would be:
    Code:
    Dim lngCounter As Long, dblSqr As Double
    Dim StartTime As Long, EndTime As Long
    
    StartTime = timeGetTime()
    
    For lngCounter = 1 To 20000000
      dblSqr = Sqr(intCounter)
    Next
    
    EndTime = timeGetTime()
    Debug.Print "It took " & (EndTime - StartTime) / 1000 & " seconds to process this loop"
    OUTPUT:
    It took 1.316 seconds to process this loop
Working...