[Coco] Why does using a decimal point instead of a zero result in faster code?
Darren A
mechacoco at gmail.com
Thu Apr 30 01:36:09 EDT 2009
On 4/29/09, John Guin wrote:
> Say gang,
>
> I remember back in the day a simple "trick" which resulted in faster BASIC
> run times. The trick was to a use a decimal point instead of 0 when using
> the value zero.
>
> For instance:
> 10 FOR I = 0 to 10000
> 20 IF I = 0 THEN PRINT "HELLO WORLD"
> 30 NEXT I
>
> Runs slower than:
>
> 10 FOR I = 0 to 10000
> 20 IF I = . THEN PRINT "HELLO WORLD"
> 30 NEXT I
>
> I can't remember if this has been asked here, but if it has, I certainly
> don't remember the answer.
>
> Any ideas?
>
It's simply due to the way the Color Basic interpreter performs an
ASCII to Floating Point conversion. Numbers in a Basic program are
stored as ASCII characters so the interpreter has to convert them into
a binary floating point representation each time they are encountered.
The conversion process starts by initializing an FP accumulator to
zero then, for each ASCII digit encountered, multiplies the
accumulator by 10 and adds the value of the digit. By eliminating the
'0' character and just using a decimal point, you avoid this multiply
- add operation.
Darren
More information about the Coco
mailing list