Is a substitution variable faster than an integer in Vic-20 basic?

The following two (functionally equivalent) programs come from the old Compute Gazette issue. The main difference is that program 1 places the target base memory cells (7680 and 38400) in a line, while program 2 first assigns them to a variable.

Program 1 runs about 50% slower than program 2. Why? I would think that adding an extra variable will add time, not subtract it!

10 PRINT"[CLR]":A=0:TI$="000000"
20 POKE 7680+A,81:POKE 38400+A,6:IF A=505 THEN GOTO 40
30 A=A+1:GOTO 20
40 PRINT TI/60:END

Program 1

10 PRINT "[CLR]":A=0:B=7600:C=38400:TI$="000000"
20 POKE B+A,81:POKE C+A,6:IF A=505 THEN GOTO 40
30 A=A+1:GOTO 20
40 PRINT TI/60:END

Program 2

+3
source share
3 answers

, BASIC , "7680" "38400" . 20 (506 ). 2 B. --- B , ---, 2 .

BASIC ( , VIC-20, -), , , , , 1 , , .

+2

76 : http://www.scribd.com/doc/33728028/Compute-Gazette-Issue-01-1983-Jul

. 30% - . , 2, , , . , :

POKE 7680 + A, 81: POKE 38400 + A

BASIC- .

+2

Access to the first defined variable will be quick; the second will be a little slower etc. Parsing multiple-valued constants requires the interpreter to re-multiply by ten. I don't know what exact tradeoffs between variables and constants are, but short variable names use less space than multi-valued constants. By the way, a constant zero can be analyzed faster if it is written as a single decimal point (without digits) than as a digit 0.

0
source

Source: https://habr.com/ru/post/1761568/


All Articles