[Coco] Color BASIC optimization challenge – scaling
alsplace at pobox.com
Wed Mar 11 06:11:41 EDT 2020
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.)
More information about the Coco