72. Top 10 speed techniques ~~~~~~~~~~~~~~~~~~~~~~~ Here is a list of techniques to increase the speed of your programs, courtesy of Bob Horne. Some are fairly well known, others may be new to you. The amount of improvement can vary from dramatic to marginal, but small improvements here and there can add up to substantial increases in speed. You should use the TIME facility to measure which parts of the program are slowest, and to assess the effect of using these techniques. You should initially concentrate your attentions on statements inside loops, whether they be FOR-NEXT loops, REPEAT-UNTIL or IF-THEN-GOTO loops, as this is where small delays tend to add up. ie. pay special attention to lines which are executed most often. By all means do break these rules if it improves clarity without slowing things down, so use your common sense! 1. Use integer variables, (especially the resident A%-Z%), and integer arrays where possible, including loop-counter variables. (ie. FOR A%=1 TO 10.) 2. When graphics are drawn with a FOR-NEXT loop, use the largest STEP size the Mode resolution will allow. (ie. 4 vertically, and 2, 4 or 8 horizontally.) 3. Miss off the loop-counter variables in NEXT statements. (ie. use NEXT rather than NEXT A%.) 4. Ensure that all unnecessary calculations are done outside loops. (eg. X*3*PI/2 inside a loop is slower than X*p, where p=3*PI/2 before the loop is entered.) Use REMs where they will be executed, then put them on the end of an existing line, rather than separately. eg b=RAD(b):REM convert to radians. 5. Don't put REMs or blank lines where they will be executed often; even though they don't actually do anything, they will slow things down. They are harmless if the program jumps round them, but don't go putting in GOTOs specially, as that's just as bad. If you must use REMs where they will be executed, then put them on the end of an existing line rather than separately. Eg: 10 b=RAD(b):REM convert to radians 6. Use multistatement lines; the fewer line numbers that are involved, the faster the program works. 7. Procedures/Functions may sometimes be faster than GOSUBs, (but you never use GOSUBS anyway, do you?) 8. Use short Procedure/Function names, try to have them all start with a different letter, and put the DEF of the Procedures called most often before the others, (ie. at a lower line number). 9. Use short variable names, and try to start them with different letters, as for Procedures. 10.FOR-NEXT loops are faster than REPEAT-UNTIL or IF-THEN-GOTO loops.