Results 1 to 4 of 4

Thread: Overflow using timeGetTime

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2019
    Posts
    150

    Overflow using timeGetTime

    I understand the signed vs unsigned long thing but why do i get an overflow error occasionally doing a subtraction between the value of the last call to timeGetTime and the current call.

    I understood that the number should just go negative in the signed long?

    cheers

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2019
    Posts
    150

    Re: Overflow using timeGetTime

    Dont worry I think I got it

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,293

    Re: Overflow using timeGetTime

    JFYI, timeGetTime is API can be hopelessly inaccurate in contrast to QueryPerformanceXxx functions.

    Code:
    Option Explicit
    
    Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
    Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
    
    Public Property Get TimerEx() As Double
        Dim cFreq           As Currency
        Dim cValue          As Currency
        
        Call QueryPerformanceFrequency(cFreq)
        Call QueryPerformanceCounter(cValue)
        TimerEx = cValue / cFreq
    End Property
    
    Private Sub Form_Load()
        Dim dblStart As Double
        
        dblStart = TimerEx
        
        '--- do stuff here
        
        Debug.Print "Elapsed " & Format$(TimerEx - dblStart, "0.000") & " sec"
    End Sub
    When I see micro-benchmarks with timeGetTime I can be positive everything else will fall apart upon closer scrutiny too.

    cheers,
    </wqw>

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2019
    Posts
    150

    Re: Overflow using timeGetTime

    Quote Originally Posted by wqweto View Post
    JFYI, timeGetTime is API can be hopelessly inaccurate in contrast to QueryPerformanceXxx functions.

    Code:
    Option Explicit
    
    Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
    Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
    
    Public Property Get TimerEx() As Double
        Dim cFreq           As Currency
        Dim cValue          As Currency
        
        Call QueryPerformanceFrequency(cFreq)
        Call QueryPerformanceCounter(cValue)
        TimerEx = cValue / cFreq
    End Property
    
    Private Sub Form_Load()
        Dim dblStart As Double
        
        dblStart = TimerEx
        
        '--- do stuff here
        
        Debug.Print "Elapsed " & Format$(TimerEx - dblStart, "0.000") & " sec"
    End Sub
    When I see micro-benchmarks with timeGetTime I can be positive everything else will fall apart upon closer scrutiny too.

    cheers,
    </wqw>
    Thanks. Its not being used for benchmarks. Milliseconds are not really useful for that anyway.

    I use WaitForSingleObject for some thread synchronization and I keep some global instrumentation that the monitoring system can look at for a high level overview of average wait etc. I use QueryPerformanceCounter when needed for more accurate stuff. This does not matter if its not that accurate. Thanks for the input.

    cheers

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