» Home » VB Fibre
Site
News
Files

Visual Basic
Strings
Math
General
Properties
Memory
Methods

Search
Testing

Inline ASM-VB
Strings
Math
General
Memory

Search
Using inline ASM
Submit!

Division vs Multiplication (update!)

Someone pointed me on the fact that I used a wrong variable type somewhere. I fixed this and tested it again, and this time, the multiplication was faster than division, which was proven otherwise in a previous test.

Declaration:
Dim lngReturn As Single Dim Action As Single

Code:
Public Sub TestOne() Action = 4 lngReturn = 10 Action End Sub Public Sub TestTwo() Action = 0.25 lngReturn = 10 * Action End Sub
The variable conversion which was required previously made the multiplication slower.

Div % faster than Mul Div (sec) Mul (sec)
304.2% 0.086051 0.021289
182.8% 0.079669 0.028168
269.8% 0.078566 0.021244
192.1% 0.077067 0.026381
261.1% 0.079152 0.02192


User contributed notes:

Author: PRoPHEZZoR (Name_Here_No_Spam at HaCKERMAiL dot COM) Date: 11:08 24/08/2004
Uhm... When working with automation, wouldn't you (If you wanna use * instead of \\) first divide the Action value with what you would normally multiply by, thus neutralizing the "optimization"?

Sorry 4 being a smart-ass, just wanna share some thoughts ;-)

Author: Tom (hurendo_kun at hotmail dot com) Date: 14:05 31/05/2005
Yes, but this assumes you want to divide in bulk by the same denominator, in which case pre-processing it once and multiplying a million times is generally faster -- but on modern FPU's it doesn't really matter.

Add user-note
Author:
E-mail (optional):
Anti spam, please enter 'ok' without quotes:
Comment: