Download cambasic - Remote Processing

Transcript
How to Maximize Execution Speed
1.
Use the pre-compiled variable A% to Z% . In an average program these will run 50% faster. U se as many as
possible, espec ially in FOR/ NEX T loops and softwar e counters.
For other var iables there is a lookup time. To minimize lookup time declare the variables at the beginning of
the progr am to for ce them to be at the beginn ing of the var iable table. Put the var iables which need to
execute fastest at the beginning.
10 A=0:B=0:C=0:A$=""
2.
Use constants rather than variables whenever possible in all functions and statements. Except for the precompiled variables above, a “ lookup” time is required.
POKE &9000,4
fastest
POKE A%,B%
fast
POKE A,B
slowest
3.
The speed of execution is independent of the length of the variable name.
4.
Place several statements on the same line. This will yield a slight increase in speed at the expense of clarity.
5.
Use INC and DEC whenever possible. T hey are m uch faster than the standar d syntax to increme nt variables.
6.
INC A%
fastest
INC A
fast
A=A+1
slowest
All string op erations a re slow . T his is especially tr ue when concatena ting strings. When pr inting, avoid
string concatenation.
PRINT A$;B$ fast
PRINT A$+B$ slow
7.
Certain mathematical operations have long execution times: multiply, divide, SIN, COS, ATN, SQR, LOG,
EXP and $.
8.
Replace a list of conditionals w ith the ON GOT O statem ent:
9.
10 ON X GOTO 200,300,400,500
fast
10
20
30
40
very slow
IF
IF
IF
IF
X=1
X=2
X=3
X+4
GOTO
GOTO
GOTO
GOTO
200
300
400
500
Even though remar ks are not executed, there is a slight amount of overhead to skip over the list number. Y ou
Program ing Tips - 1