# [Coco] Color BASIC optimization challenge – scaling

Walter Zambotti zambotti at iinet.net.au
Fri Mar 13 01:22:56 EDT 2020

```Try changing the inner loop to remove all calculations like this

115 P2=P+32:H2=P+H*32:BK\$=STRING\$(W,175)
120 FOR A=P2 TO H2 STEP 32
130 PRINT @A,BK\$
140 NEXT A

I believe I chopped 7 seconds off the time.

-----Original Message-----
From: Coco [mailto:coco-bounces at maltedmedia.com] On Behalf Of Allen Huffman
Sent: Wednesday, 11 March 2020 6:12 PM
To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
Subject: [Coco] Color BASIC optimization challenge – scaling

I just posted an article showing a BASIC program that scales a block (on the 32-column text screen):

https://subethasoftware.com/2020/03/10/color-basic-optimization-challenge-scaling/#comment-34240

In it, I challenge folks to optimize the code (leaving the basic framework/algorithm intact) to make it faster.

Any takers? Here is the BASIC code that runs 100 iterations then reports an estimate of how long it took. The sample takes just over 25 seconds:

0 REM scale.bas
10 SW=32/4 ' SCALE WIDTH
20 SH=16/3 ' SCALE HEIGHT
30 SM=.1   ' SCALE INC/DEC
40 S=.5    ' SCALE FACTOR
70 TM=TIMER:FOR Z=1 TO 100
80 W=INT(SW*S)
90 H=INT(SH*S)
100 P=15-INT(W/2)+(7-INT(H/2))*32
110 CLS
120 FOR A=1 TO H
130 PRINT at P+A*32,STRING\$(W,175)
140 NEXT A
150 S=S+SM
160 IF H<1 OR H>15 THEN SM=-SM:S=S+(SM*2)
170 NEXT Z
180 ' 60=NTSC 50=PAL
190 PRINT:PRINT (TIMER-TM)/60;"SECONDS"

Rules:
• You must leave the basic algorithm intact (the SW, SH, S and SH stuff with all the math). You can rename variables, change the representation of values, speed up PRINTing, etc. but the core program flow should remain the same.
* For bonus points, you are welcome to rewrite the program (in BASIC) to improve upon the algorithm in any way that makes sense, provided it achieves the same results (including the 1 to 100 benchmark loop).

I have a follow-up article that I will post later that details the major optimizations that I could think of.

George Phillips has already responded, and has a different type of optimization I had not considered, which almost doubles the speed.

Cheers,
--
Allen Huffman - PO Box 7634 - Urbandale IA 50323 - 515-999-0227 (vmail/TXT only) http://www.subethasoftware.com - https://www.facebook.com/subethasoftware
Sent from my MacBook.

P.S. Since 4/15/2014, I have earned over \$4050! Sign up using my link and I get credit:
http://swagbucks.com/refer/allenhuffman (Ask me for the tip/howto doc.)

--
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco

```