|
-
Apr 14th, 2011, 11:43 AM
#1
Thread Starter
Addicted Member
Optimizing code for speed
Hi,
My code makes quite extensive calculations, and I would like to speed up the operations as fast as possible by eliminating one line of code or changing the dimmension of a variable.
I appreciate you comments.
Version 1.
tempMemI(i) is just Integers array
Dim Temp As Integer
Dim Total As Long
For i = 0 to MemLen
If tempMemI(i) = -32768 Then
Temp = 32767
Else
Temp = Abs(tempMemI(i))
End If
Total = Total + Temp
Next
AvgValue(BufferNo) = Total / TempBuff
Version 2.
Dim Temp As Long
Dim Total As Long
For i = 0 to MemLen
Temp = Abs(tempMemI(i))
Total = Total + Temp
Next
AvgValue(BufferNo) = Total / TempBuff
Which version is better for speed calculation?
Thanks,
jas
Added April 19th
Apparently version 2 above does not work as I thought.
Casting Temp as Long does not fix the problem.
Just trying this in Immediate window:
?abs(tempMemI(i)) > where value of tempMemI(i) = -32768
causes the overflow error.
How to optimize that code for speed then?
jas
Last edited by jastrzebiec; Apr 19th, 2011 at 05:31 PM.
Reason: new info
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
|