# 2023-05-06 Benchmarking BASIC on a Tandy CoCo1

Doing a little more retro computing, I wondered just how fast - or slow - various BASIC routines were on the Tandy Color Computer, and set about trying to come up with a relatively sane set of benchmarks, focusing mainly on the various mathematical routines. It turns out, most are quite good, but the transcendental functions are understandably expensive. Interestingly, the cost of parsing floating point constants varies greatly with the number of digits after the decimal point. This also means that I/2 is faster than I*0.25.

The code uses the built-in TIMER variable, which ticks at 50 or 60Hz depending where you are in the world.

10 ' BENCHMRK 2023-05-06
20 ' PAUL RIPKE STIX@STIX.ID.AU
30 I=0:A=0:PI=ATN(1)*4:C=180/PI:CC=360/PI
40 INPUT"OUTPUT TO PRINTER (Y/(N))";A$50 IF A$="Y"THEND=-2ELSED=0
60 PRINT #D,"FUNCTION";TAB(25);" TICKS"
70 FOR F=1 TO 28
80 READ F$90 TIMER=0:ON F GOSUB 150,170,190,210,230,250,270,290,310,330,350,370,390,410,430,450,480,500,520,540,570,590,610,630,650,670,690,710:E=TIMER 100 PRINT #D,F$;": ";TAB(25);
110 PRINT #D,USING "###.##";E/6
120 NEXT F
130 END
140 DATA "NULL"
150 FORI=1TO100:NEXT:RETURN
160 DATA "CONST INT 1D"
170 FORI=1TO100:A=9:NEXT:RETURN
180 DATA "CONST INT 3D"
190 FORI=1TO100:A=999:NEXT:RETURN
200 DATA "CONST INT 9D"
210 FORI=1TO100:A=999999999:NEXT:RETURN
220 DATA "CONST INT 14D"
230 FORI=1TO100:A=99999999999999:NEXT:RETURN
240 DATA "CONST FL 3D"
250 FORI=1TO100:A=0.123:NEXT:RETURN
260 DATA "CONST FL 9D"
270 FORI=1TO100:A=3.14159266:NEXT:RETURN
280 DATA "CONST FL 14D"
290 FORI=1TO100:A=3.14159265358979:NEXT:RETURN
300 DATA "ASSIGN"
310 FORI=1TO100:A=PI:NEXT:RETURN
320 DATA "INC"
330 FORI=1TO100:A=I+1:NEXT:RETURN
340 DATA "MUL"
350 FORI=1TO100:A=I*I:NEXT:RETURN
360 DATA "MUL FL"
370 FORI=1TO100:A=PI*PI:NEXT:RETURN
380 DATA "DIV"
390 FORI=1TO100:A=I/C:NEXT:RETURN
400 DATA "HALF BY MUL"
410 FORI=1TO100:A=I*0.5:NEXT:RETURN
420 DATA "HALF BY DIV"
430 FORI=1TO100:A=I/2:NEXT:RETURN
440 DATA "SIN+DIV"
450 FORI=1TO100:A=SIN(I/C):NEXT:RETURN
460 DATA "TAN+DIV"
470 'TAN(90) UNDEFINED!
480 FORI=1TO100:A=TAN(I/CC):NEXT:RETURN
490 DATA "ATN"
500 FORI=1TO100:A=ATN(I):NEXT:RETURN
510 DATA "SQRT"
520 FORI=1TO100:A=SQR(I):NEXT:RETURN
530 DATA "LOG"
540 FORI=1TO100:A=LOG(I):NEXT:RETURN
550 DATA "EXP+DIV"
560 ' EXP(100) OVERFLOWS!
570 FORI=1TO100:A=EXP(I/2):NEXT:RETURN
580 DATA "SQRT BY LOG+EXP"
590 FORI=1TO100:A=EXP(LOG(I)/2):NEXT:RETURN
600 DATA "POWER(SMALL)"
610 FORI=1TO100:A=I^2:NEXT:RETURN
620 DATA "POWER(LARGE)"
630 FORI=1TO100:A=2.2^I:NEXT:RETURN
640 DATA "AND"
650 FORI=1TO100:A=IAND3:NEXT:RETURN
660 DATA "XOR"
670 FORI=1TO100:A=(IOR3)ANDNOT(IAND3):NEXT:RETURN
680 DATA "RND(0)"
690 FORI=1TO100:A=RND(0):NEXT:RETURN
700 DATA "RND(2)"
710 FORI=1TO100:A=RND(2):NEXT:RETURN


Output captured from xroar closely matches the output on my Coco1, and is far easier to grab:

FUNCTION                  TICKS
NULL:                      1.17
CONST INT 1D:              2.50
CONST INT 3D:              4.67
CONST INT 9D:             11.17
CONST INT 14D:            17.33
CONST FL 3D:              14.50
CONST FL 9D:              36.17
CONST FL 14D:             61.50
ASSIGN:                    2.33
INC:                       3.83
MUL:                       4.00
MUL FL:                    5.83
DIV:                       5.83
HALF BY MUL:               7.17
HALF BY DIV:               5.67
SIN+DIV:                  31.00
TAN+DIV:                  54.50
ATN:                      44.50
SQRT:                     50.00
LOG:                      23.83
EXP+DIV:                  28.33
SQRT BY LOG+EXP:          52.17
POWER(SMALL):             50.00
POWER(LARGE):             55.67
AND:                       2.83
XOR:                       7.00
RND(0):                    6.00
RND(2):                   10.50