How to maximize execution speed – Remote Processing CAMBASIC User Manual

Page 24

Advertising
background image

Program ing Tips - 1

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 pre-
compiled 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.

INC A%

fastest

INC A

fast

A=A+1

slowest

6.

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:

10 ON X GOTO 200,300,400,500

fast

10 IF X=1 GOTO 200

very slow

20 IF X=2 GOTO 300
30 IF X=3 GOTO 400
40 IF X+4 GOTO 500

9.

Even though remar ks are not executed, there is a slight amount of overhead to skip over the list number. Y ou

Advertising