Numerical Calculations and Loops Are Faster with Integers (36901)
This article was previously published under Q36901
SUMMARY
The time needed to process numbers as floating-point numbers is
significantly longer than with integers. Since the default data type
is single-precision floating-point numbers, it is quite common for
people to use a floating-point variable to represent a number that
could be represented as an integer or long. A FOR-NEXT loop that does
nothing takes approximately six times as long to run when the index
variable is specified as a single-precision number rather than as an
integer.
This information applies to Microsoft QuickBasic Versions 4.00, 4.00b,
and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b for
MS-DOS and MS OS/2, and to Microsoft Basic PDS Version 7.00 for MS-DOS
and MS OS/2.
Modification Type: |
Minor |
Last Reviewed: |
1/9/2003 |
Keywords: |
KB36901 |
|