[Coco] Color BASIC optimization challenge – scaling
zambotti at iinet.net.au
Fri Mar 13 01:22:56 EDT 2020
Try changing the inner loop to remove all calculations like this
120 FOR A=P2 TO H2 STEP 32
130 PRINT @A,BK$
140 NEXT A
I believe I chopped 7 seconds off the time.
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):
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
120 FOR A=1 TO H
130 PRINT at P+A*32,STRING$(W,175)
140 NEXT A
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"
• 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.
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
More information about the Coco