VB and VBA Users Source Code: Faster way to divide integers values
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Faster way to divide integers values
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Friday, February 01, 2002
Hits:
908
Category:
Visual Basic General
Article:
Most developers will use the floating point division operator ("\") for all numerical divisions. However, when dividing integers the integer division operator ("/") is more than twice as fast. 'Demonstrates the speed gain from using "\" integer divisions Sub Test() Dim siTimer As Single, lThisLoop As Long, lThisVal As Long siTimer = Timer For lThisLoop = 1 To 10000000 lThisVal = 2 \ 2 'Notice the "\" (integer) operator is used Next Debug.Print "Using Integer Point Division: " & Timer - siTimer siTimer = Timer For lThisLoop = 1 To 10000000 lThisVal = 2 / 2 'Notice the "/" (floating point) operator is used Next Debug.Print "Using Floating Point Division: " & Timer - siTimer End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder