Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

168 32 Speeding up programs and saving memory space For some applications it is important that a program runs as quickly as possible and a few tips are given here which will, together, substantially increase the execution speed of programs. In other applications space may be at a premium and other suggestions are given for saving space. Sometimes there is a trade-off between the size of a program and speed and the user will have to decide which is more important. The most dramatic saving that can be made is in the speed of execution of programs.

The use of integer variables (eg WEIGHT% ), and especially of the resident integer variables A% to Z% , will result in execution times as little as 50% of those achieved with ‘real’ variables. Again, integer division ( DIV ) is much faster than normal division when working with integers. Using integer arrays rather than real arrays will save 20% of the memory required. Execution speed can also be increased in the following ways. 1. Allocate variable names with an even spread throughout the alphabet – so don’t start all your variables with ‘F’, for example. 2. Omit the control variable after the word NEXT – eg say NEXT rather than NEXT X . This saves a reasonable amount of time. 3.

REPEAT...UNTIL loops are much faster than IF...THEN...GOTO loops. 4. Procedures are faster than GOSUB s, and it is faster to pass parameters to a procedure than to use global variables – ie do use PROCBOX(X,Y,Z) rather than PROCBOX . 5. If you have a line which contains a lot of ‘integer’ arithmetic and a little ‘real’ arithmetic then, if possible, place the integer work at the start of the line where it will be executed first. 6. Have as few line numbers as possible – ie use long lines and spread the line numbers out rather than re-numbering with an interval of 1. An interval of 10 is good.

As far as space saving is concerned the following can be tried – but both reduce the readability of programs and should not be used unless it is really necessary.