Commodore VIC-20 User Manual page 164

Hide thumbs Also See for VIC-20:
Table of Contents

Advertisement

150
The VIC 20 User Guide
Keeping time injiffies is useful for timing program speed. This lets you
test the efficiency of a program. Consider the following short program:
10 PRINT":.' ] III!IIKEYBOARD T£ST!IE!IE":PRINT
20 FOR 1=32 TO 127
30 PRINT CHR$(I);
40 NEXT
·1
.5~
FOR J"161 TO 255
60
PRINT CHR$(J);
70 NEXT
J
S0 PRINT:PRINT:PRINT"!lEilEEND TEST!lEiIE"
You can compute execution time for this program as follows:
1. TI (or TIME) is assigned to a variable at the start of the time test.
2. TI (or TIME) is checked at the end of the time test. Subtract the first
value of TI from the new TI value. This will give you the amount of
jiffy time it took to process the program in question.
The following listing adds these steps:
10 PRINT":' ) !!!lEKEYBOARD TEST!IE!IE":PRINT .
15
A=TI
20 FOR 1=32 TO 127
30 PRINT CHRS(I)i
40 NE>:T
50 FOR
J=161
TO 255
60 PRINT CHR$(J);
70 NEXT
80 PRINT:PRINT:PRINT"!IE!lEEND TEST*!IE"
10e PRINT:PRINT"TI
=
";TI-A
As the program continues, TI increments 60 times every second. Line
100 subtracts the first value of TI (A) from TI's latest value. It took 41 jiffies
to display the keyboard characters. Divide jiffy time (41 jiffies) by 60 (the
number of jiffies in a second).
41/60 = 0.6833
Thus, it took 0.6833 seconds to run the program.
RANDOM NUMBERS
Random numbers may be used in games you program on your VIC 20;
they have more practical uses in statistics and other areas as well. The VIC

Advertisement

Table of Contents
loading

Table of Contents