Results 1 to 27 of 27

Thread: speed?

Hybrid View

  1. #1
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: speed?

    I believe it is faster. But I think it may make sence to use & next to a variable rather than a number. What I mean by this is this right here:

    Dim A As Long, B as Long

    B& = 1
    A& = B&

    Simply saying A = 1 since variables represent memory locations to store data just shows that you are storing the value 1 into the memory location of A. Values themselves don't really have a data type. But Variables on the other hand do to represent the type of data to store and allocate a number of bytes for that memory location depending on what data type you declared it as. Like 2 Bytes for Integer variables and 4 Bytes for Long variables has been allocated for that memory location.

    Now A = B on the other hand, you are saying that you want the memory location's data to be copied into A. Putting the & (Long data type symbol) next to all the variables that are declared as long will let the compiler know what data types they are and prevent conversions from one data type to another. In my opinion, A& = B& will be saying that B's 4 byte long integer register's data will be copied into A's 4 byte long integer register. Saying A = B on the other hand will be saying B's unknown register's data will be copied into A's unknown register. And extra assembly code will be added to convert them to their proper data types, thus slowing things down.




    I'm know assembly guru or anything like that, but I believe they can answer that better than I can.

  2. #2

    Thread Starter
    Banned nareth's Avatar
    Join Date
    Jun 2004
    Posts
    1,206

    Re: speed?

    oh ok thank you, i was thinking something like that.

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: speed?

    I made a test with these two codes:

    Code:
        For X = 1 To ITERATIONS
            A& = 1&
        Next X
    Code:
        For X = 1 To ITERATIONS
            A = 1
        Next X
    There was no speed difference at all. Compiled, all advanced optimizations turned on, ten million iterations and ran many times.

  4. #4

    Thread Starter
    Banned nareth's Avatar
    Join Date
    Jun 2004
    Posts
    1,206

    Re: speed?

    can you post a img of the options?

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: speed?

    In my opinion, A& = B& will be saying that B's 4 byte long integer register's data will be copied into A's 4 byte long integer register. Saying A = B on the other hand will be saying B's unknown register's data will be copied into A's unknown register. And extra assembly code will be added to convert them to their proper data types, thus slowing things down.
    If you are using Option Explicit and have declared A As Long and B As Long, no data type conversion will be done. Compiler is smart enough to optimize that.

  6. #6

    Thread Starter
    Banned nareth's Avatar
    Join Date
    Jun 2004
    Posts
    1,206

    Re: speed?

    Quote Originally Posted by nareth
    can you post a img of the options?
    ?????

  7. #7

    Thread Starter
    Banned nareth's Avatar
    Join Date
    Jun 2004
    Posts
    1,206

    Re: speed?

    also another question..

    If UCase$(Account.Name) <> UCase$(Param(1)) Then
    strcomp(UCase$(Account.Name),UCase$(Param(1)),vbTextCompare)
    If UCase(Account.Name) <> UCase(Param(1)) Then
    strcomp(UCase(Account.Name),UCase(Param(1)))

    wich is faster?

  8. #8
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: speed?

    can you post a img of the options?
    I don't understand what you mean with that.


    The one with $ is faster. In this case, UCase$ is string based, while UCase is variant based. There will be data type conversion when there is no $.

    Then... as for the optimization, you have lots and lots to improve there.

    strcomp(UCase$(Account.Name),UCase$(Param(1)),vbTextCompare)

    If you are doing UCase$(), you don't need to do text compare, because of UCase$. You could actually take UCase$() out and just have text compare, because it is faster than calling UCase$() two times.


    Then about the fastest comparison you can get:

    Code:
    'first check the length of the string (LenB is faster than Len)
    If LenB(Account.Name) = LenB(Param(1)) Then
        'then check if we can find it
        If InStr(1, Account.Name, Param(1), vbTextCompare) = 1 Then
            'it is a match
        End If
    End If
    Last edited by Merri; Dec 17th, 2004 at 01:14 PM.

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