|
-
Dec 17th, 2004, 11:48 AM
#1
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.
Last edited by Jacob Roman; Dec 17th, 2004 at 11:52 AM.
-
Dec 17th, 2004, 11:53 AM
#2
Thread Starter
Banned
Re: speed?
oh ok thank you, i was thinking something like that.
-
Dec 17th, 2004, 12:14 PM
#3
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.
-
Dec 17th, 2004, 12:30 PM
#4
Thread Starter
Banned
Re: speed?
can you post a img of the options?
-
Dec 17th, 2004, 12:37 PM
#5
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.
-
Dec 17th, 2004, 12:40 PM
#6
Thread Starter
Banned
Re: speed?
 Originally Posted by nareth
can you post a img of the options?
?????
-
Dec 17th, 2004, 12:58 PM
#7
Thread Starter
Banned
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?
-
Dec 17th, 2004, 01:07 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|