Contents / Part 3 / Previous chapter / Next chapter / Index


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 spree. 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 (e.g. 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. i.e., say NEXT rather than NEXT X. This saves quite a lot of time.
  3. REPEAT...UNTIL loops are much faster than IF...THEN GOTO loops.
  4. Procedures are faster than GOSUBs, and it is faster to pass parameters to a procedure than to use global variables. i.e, 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 - i.e. 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 all reduce the readability of programs and should not be used unless it is really necessary.

  7. Omit spaces wherever possible - but you must keep a space or a % or $ sign or some other separator before most keywords to avoid ambiguity. If a variable FRED is in use then you must write

    Y=FRED OR MARY

    and not

    Y=FREDORMARY

    In the latter case the computer will look for the variable FREDORMARY rather than the two variables FRED and MARY. The space after OR is not required.

  8. Omit REM statements.

Exit: BBC Microcomputer User Guide; Kasoft Typesetting; Archer


The BBC Microcomputer User Guide was written by John Coll and edited by David Allen for the British Broadcasting Corporation.

Optical character recognition and original formatting effort by Mark Usher.

HTML version maintained by: Kade "Archer" Hansson; e-mail: archer@dialix.com.au

Last updated: Monday 12th February 2001