Results 1 to 3 of 3

Thread: Just a tip re: Speeding Mathematical Operations

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411
    While looking into a way to speed up the filling of an array of one million elements (type Single), I came across something I never knew about which I thought others may be able to use in the future.

    I have tested the first of these on a large array of Integers and I noticed no difference in the speed at all. I guess I have to do more like a billion operations before I'd notice a difference OR this is not the way it is done in VB...

    The only difference I did notice was that if I changed my array to type Double, I had an improvement in the time to fill the array. This would be due to VB not having to convert the result from Double to Single in order to fit my array (see note 2).

    From "Microsoft Office 2000/Visual Basic Programmer's Guide"

    Mathematical Operations
    The following points provide suggestions for ways to speed up operations on numbers:

    When performing division on integers, use the integer division operator (\) rather than the floating-point division operator (/), which always returns a value of type Double regardless of the types of the numbers being divided.


    Keep in mind that any time you use a Single or Double value in an arithmetic expression with integer values, the integers are converted to Single or Double values, and the final result is a Single or Double value. If you're performing several operations on a number that is the result of an arithmetic operation, you may want to explicitly convert the number to a smaller data type.
    Cheers
    Paul Lewis

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Thanks for the tip.

  3. #3
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    One tiny problem: it will screw your function if you need decimal places. It will also screw your function because of rounding errors. Otherwise, it rules. I love it.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

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