CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2012
    Posts
    3

    VB 6 calculates differently for 'No Optimiza' and 'Optimize for Fast Code' exe builds

    There is a situation here where the exe generated with options being set to "No Optimization" produces output which differs from the output of the exe generated with options being set to "Optimize for Fast Code".
    There are lot of calculations, iterations, probability and std deviation calculations involved but we cant figure out how and where VB Calculation differs in "No Optimize" build and "Optimize for fast Code" build.

    The code is too big to include it in here. Would be really helpful if someone can explain what exactly VB 6 does during "Optimize for Fast Code" that is different from 'No Optimization'

    Thanks,
    Arun

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB 6 calculates differently for 'No Optimiza' and 'Optimize for Fast Code' exe bu

    Should be no different, only FASTER...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2012
    Posts
    3

    Re: VB 6 calculates differently for 'No Optimiza' and 'Optimize for Fast Code' exe bu

    Yes, ideally it should be. But the output actually differs. As I said its kind of a forecasting application which involves lots of calculations on probability and std.deviations. I am trying to figure out where the difference happens but no luck until now.

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: VB 6 calculates differently for 'No Optimiza' and 'Optimize for Fast Code' exe bu

    What hardware, especially CPU and which OS are you running?
    I also never heared about differing calc results...

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: VB 6 calculates differently for 'No Optimiza' and 'Optimize for Fast Code' exe bu

    I do not think the OP means that calculations have different results in your exe but rather that the way the compiler creates the output is different which it is of course. I do not know exactly what the compiler does at compile time with the various options set. Never really had a need to know.
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB 6 calculates differently for 'No Optimiza' and 'Optimize for Fast Code' exe bu

    One compiles to P-Code by default. Operates slower. Mostly, no string optimization
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: VB 6 calculates differently for 'No Optimiza' and 'Optimize for Fast Code' exe bu

    I think this site put's it appropriately...visualbasic freetutes

    think about what it takes to develop an optimizing compiler. It isn’t easy to determine precisely how to handle every conceivable combination of factors governing the use of an optimization. Detecting when it is safe to move an instruction out of a loop or when a particular register value ought to be retained is no mean feat, and it is possible that the optimizer may make a mistake.

    In other words, the opportunity to optimize one’s code is also another opportunity to introduce a bug.
    You Calculations obviously pushed the Code optimizer to the limit and it's failed..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  8. #8
    Join Date
    Feb 2012
    Posts
    3

    Re: VB 6 calculates differently for 'No Optimiza' and 'Optimize for Fast Code' exe bu

    Quote Originally Posted by WoF View Post
    What hardware, especially CPU and which OS are you running?
    Intel Core2DUO and Win7

    @GremlinSA

    thanks for the link
    ----------------------------------------------
    We are now logging the calculations in a file and could see some differences in rounding of 'double' datatypes during auto type casting.

    I will update once we are conclusive on what makes the difference in output.

    Thanks,
    Arun
    Last edited by arunchristopher; February 26th, 2012 at 12:53 AM.

  9. #9
    Join Date
    Aug 2012
    Posts
    2

    Re: VB 6 calculates differently for 'No Optimiza' and 'Optimize for Fast Code' exe bu

    I have a similar problem with Compile for Fast Code versus Compile with No Optimization.
    The following code reproduces the problem -
    Can anyone else try this program on their computer to see if they get the same results?

    Code:
    Option Explicit
    
    Const COL_FLTS = 1
    Const COL_FTIME = 2
    
    Public FltData(100, 7, 1) As Long
    Public xCOL_FTIME As Long, xCOL_FLTS As Long
    
    
    Sub Main()
        Dim x As Long, j As Long
        Dim rw As Long, mon As Long, comment As String
        rw = 1
        mon = 0
        comment = "main "
        xCOL_FLTS = 1: xCOL_FTIME = 2
        
    Call testLongArray(rw, mon, "testlong #1")
    'Call testLongArray(rw, mon, "testlong #2")
    
    
    FltData(rw, COL_FLTS, mon) = FltData(rw, COL_FLTS, mon) + 1000
    x = FltData(rw, COL_FTIME, mon) + 100
    FltData(rw, COL_FTIME, mon) = x
    For j = 1 To 12
    Next j
    If x <> FltData(rw, COL_FTIME, mon) Then
        MsgBox (comment & " no joy " + Str(x) + Str(FltData(rw, COL_FTIME, mon)) + Str(FltData(rw, COL_FLTS, mon)))
    Else
        MsgBox (comment & " OK " + Str(x) + Str(FltData(rw, COL_FTIME, mon)) + Str(FltData(rw, COL_FLTS, mon)))
    End If
    
    Call testLongArray(rw, mon, "testlong #3 ")
    End Sub
    
    Function testLongArray(ByVal rw As Long, ByVal mon As Long, ByVal comment As String)
        Dim j As Long, x As Long
        
    FltData(rw, COL_FLTS, mon) = FltData(rw, COL_FLTS, mon) + 10
    x = FltData(rw, COL_FTIME, mon) + 100
    FltData(rw, COL_FTIME, mon) = x
    For j = 1 To 12
    Next j
    If x <> FltData(rw, COL_FTIME, mon) Then
        MsgBox (comment & " no joy" + Str(x) + Str(FltData(rw, COL_FTIME, mon)) + Str(FltData(rw, COL_FLTS, mon)))
    Else
        MsgBox (comment & " OK " + Str(x) + Str(FltData(rw, COL_FTIME, mon)) + Str(FltData(rw, COL_FLTS, mon)))
    End If
    
    End Function
    Last edited by GremlinSA; August 30th, 2012 at 02:03 AM. Reason: Changed Font tags to Code tags

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