Results 1 to 27 of 27

Thread: TimerEx, hi precision timer using QueryPerformanceCounter

Threaded View

  1. #17
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,797

    Re: TimerEx, hi precision timer using QueryPerformanceCounter

    Personally, I'm still thinking we're picking at nits. I seriously doubt that calls to any TimerEx are going to be within any tight loop. And, even if they are, I seriously doubt that the differences we're looking at are going to have any effect that's noticeable to within 4 or 5 (maybe more) decimal places.
    I just told about how the VB6 does generally such things under the hood. These things are the general ones and don't affect (nearly) within the current situation/tests. I'm very embarrassed and i don't want to hijack the current thread to provide the more significant tests but if you don't mind i show the more significant case (and exactly attached the TLB ).
    Once i had the discussion about the VB6 performance on the russian forum and we tested the Rnd function. I wrote the test of the random generation with the module, the class and the pure-VB-Rnd function. Of course all the analogs don't implement all the functionality of the Pure-VB-Rnd function (like the thread-independence, repeating etc.) but make the main task - the generation of random numbers between 0...1. That's code:
    The main form:
    Code:
    Option Explicit
    
    Private Const ITERATIONS = 20000000
    
    Private Sub Form_Click()
        Dim fR1()   As Single
        Dim fR2()   As Single
        Dim fR3()   As Single
        Dim fRes1   As Currency
        Dim fRes2   As Currency
        Dim fRes3   As Currency
        Dim lIndex  As Long
        Dim cRndObj As New CRnd
        Dim cFreq   As Currency
        Dim cValue  As Currency
        Dim cValue2 As Currency
        
        ReDim fR1(ITERATIONS - 1)
        ReDim fR2(ITERATIONS - 1)
        ReDim fR3(ITERATIONS - 1)
        
        QueryPerformanceFrequency cFreq
        QueryPerformanceCounter cValue
        
        Set cRndObj = New CRnd
        
        For lIndex = 0 To ITERATIONS - 1
            fR1(lIndex) = cRndObj.MyRnd()
        Next
        
        QueryPerformanceCounter cValue2
        
        fRes1 = (cValue2 - cValue) / cFreq
        
        modRnd.InitRnd
        
        For lIndex = 0 To ITERATIONS - 1
            fR2(lIndex) = modRnd.MyRnd()
        Next
        
        QueryPerformanceCounter cValue
        
        fRes2 = (cValue - cValue2) / cFreq
        
        For lIndex = 0 To ITERATIONS - 1
            fR3(lIndex) = Rnd()
        Next
        
        QueryPerformanceCounter cValue2
        
        fRes3 = (cValue2 - cValue) / cFreq
        
        MsgBox "Obj " & Format$(fRes1, "0.00000") & vbNewLine & _
               "Mod " & Format$(fRes2, "0.00000") & vbNewLine & _
               "VBRnd " & Format$(fRes3, "0.00000")
    
        For lIndex = 0 To ITERATIONS - 1
            
            ' // Checking
            If fR2(lIndex) <> fR1(lIndex) Or _
               fR2(lIndex) <> fR3(lIndex) Then Stop
               
        Next
    
    End Sub
    CRnd class:
    Code:
    Option Explicit
    
    Dim oldVal  As Long
     
    Public Function MyRnd() As Single
        Dim bIsInIde    As Boolean
        
        Debug.Assert MakeTrue(bIsInIde)
        
        If Not bIsInIde Then
            oldVal = (&HFFC39EC3 - oldVal * &H2BC03) And &HFFFFFF
        Else
        
            ' // This code won't added to EXE
            GetMem4 CCur(429101.0243@ - (CCur(oldVal / 10000) * 179203@)), oldVal
            oldVal = oldVal And &HFFFFFF
            
        End If
    
        MyRnd = oldVal / 16777216
        
    End Function
    
    Private Sub Class_Initialize()
        oldVal = 327680
    End Sub
    modRnd.bas module:
    Code:
    Option Explicit
    
    Dim oldVal  As Long
     
    Public Function MyRnd() As Single
        Dim bIsInIde    As Boolean
        
        Debug.Assert MakeTrue(bIsInIde)
        
        If Not bIsInIde Then
            oldVal = (&HFFC39EC3 - oldVal * &H2BC03) And &HFFFFFF
        Else
        
            ' // This code won't added to EXE
            GetMem4 CCur(429101.0243@ - (CCur(oldVal / 10000) * 179203@)), oldVal
            oldVal = oldVal And &HFFFFFF
            
        End If
    
        MyRnd = oldVal / 16777216
        
    End Function
    
    Public Sub InitRnd()
        oldVal = 327680
    End Sub
    
    Public Function MakeTrue( _
                    ByRef bIsInIde As Boolean) As Boolean
        bIsInIde = True
        MakeTrue = True
    End Function
    The results:
    IDE:
    ---------------------------
    Project1
    ---------------------------
    Obj 7,68400

    Mod 6,32100

    VBRnd 0,99810
    ---------------------------
    ОК
    ---------------------------
    EXE (with the optimizations):
    ---------------------------
    Project1
    ---------------------------
    Obj 1,03530

    Mod 0,15190

    VBRnd 1,44850
    ---------------------------
    ОК
    ---------------------------
    The std-module implementation is almost 7 times faster than Class implementation and almost 10 times! faster than pure-vb-rnd function.
    Attached Files Attached Files

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