Commodore Computer C16 Manual de usuario Pagina 13

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 14
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 12
BASIC OPTIMIZATION
The following is true for all versions of the 8 bit CBM Basic and is not
particular for Basic 3.5. (At least I think so).
GOTO and GOSUB
Because of the format of the basic (see page 10), where every basic line only have
one pointer to the next line and none to the previous, then jumps (GOTO and GOSUB)
will take different time to execute depending on the situation. Jumps to lines
just below the current one will be very fast, while jumps to lines above the
current line will be very fast for the first lines of the program but slower and
slower the lower down in the program the line is. So if you have a big program and
on the last line you jump one line up to the second last line, then this will be
quite slow as the basic will have to go through every line pointer in the program.
The RETURN command is however always of the same speed.
The tip here is to always put your heavy main routine FIRST in your program, only
preceded by one line that just jumps down to the parts setting up your program
etc. Then to go back to the main routine at the second first line. For example:
0 GOSUB 500 : REM SETUP EVERYTHING
1 ...Main routine
Heavily used subroutines should also be put as high as possible or just below the
calling routine.
When your program is ready, you can also renumber it with RENUMBER 0,1
This way the line numbers will be as small as possible, saving space and also
speeding it up a little.
VARIABLES
Variables are faster than constants, as long as you don't have too many variables.
For example:
A=132:FORT=1TO100:B=PEEK(A):NEXT
is faster than:
FORT=1TO100:B=PEEK(132):NEXT
Another important issue is that different variables has different speed! The thing
to remember here is that the variables used first in the program is the ones that
will be the fastest. So a good way to speed your program up is to analyze your
heavy routine to see which variables that are used the most. Then just use them
(set some value to them) the first thing you do in your program. For example, on
line number 0:
0 X=1:L=1:T=1:R=1
After that, X will be fastest, followed by L, and then T, and then R...
One could be fooled to think that integer variables (A% etc) would be faster than
floating point variables (A etc), but it's the other way around! Normal floating
point variables are the fastest.
TESTING SPEED
To test your routine for speed improvements, you can use the TI variable like
this:
10 E=TI
.
.
. your routine
.
.
120 PRINT TI-E
The faster it gets, the lower is the value displayed.
13
Vista de pagina 12
1 2 ... 8 9 10 11 12 13 14

Comentarios a estos manuales

Sin comentarios