Authors
Publication
Pub Details
Date
Pages
Techniques for making BASIC faster.
Last time we discussed four ways of speeding up BASIC. In this article we will discuss eight more ways!
- When printing to the screen avoid scrolling the screen, this is a slow operation. Instead it is much faster to clear the screen and then print what you want.
- Eliminate unnecessary commands and lines. On the TS2G68 use multiple command lines. For example instead of . . .
10 PRINT ’’HELLO"
20 INPUT A$
Why not write one Line, as foLlows;
10 PRINT "HELLO” : INPUT A$
This will help speed up the program. REM statements are nice and make a program easy to follow. But REM statements do slow down the program a bit. Once the program is completed why not eliminate those REM statements? If you find it necessary to keep those REM statements in the program why not bypass them. If you start a routine with the following:
100 REM Alphabetizing Routine
110 FOR 1=1 TO N
It is unnecessary for the computer to read Line 100. Why not use GOTO 110 or GOSUB 110 instead of GOTO 100 or GOSUB 110, This will let the computer skip right over 100 without reading it.
- Minimize GOTOs and GOSUBs . Although these commands are used often and are fairly quick they do slow down the computer somewhat. Their arguments must be converted from decimal to binary integer. So choose and place your GOTOs and GOSUBs carefully.
- Write your programs in a clear, structured manner. A program that jumps around a lot slows down the computer considerably. Place the most frequently used program routines near the front of the program this will save time as the computer always starts at the beginning of the program to find a particular routine.
- COSUB is faster than GOTO if you will be coming back to the same part of the program later. This is because RETURN is fast. The location is stored in binary and is jumped to immediately. Also a FOR… NEXT loop can be very fast for mathematical calculations. All necessary tests are performed in machine code when using a FOR… NEXT loop.
- IF… THEN is a very fast BASIC function. But it can also be made to work quicker. A statement IF X=1 AND Y>1 THEN…, will perform quicker if written IF X=1 THEN IF Y+Z>1 THEN… There may not seem to be much difference in these two statements but the second one will run a bit faster. The second statement will run very much quicker when X does not equal 1. If X is not 1 it will jump to the next program line without reading the rest of the line. While the first statement will be read in its entirity.
- A FOR… NEXT loop can be very fast for mathematical calculations. All necessary tests are performed in machine code when using a FOR… NEXT loop. The FOR… NEXT loop saves time for the same reason the GOSUB… RETURN statement does. All necessary information is in binary, which saves the computer from converting from decimal to binary.
- Another way to speed up a BASIC program is to insert a Machine Code routine for large programming tasks. Alphabetizing and large calculations can be done much quicker with a machine code routine. But the time spent in developing a machine code routine may not be worth the time saved.
I hope that these 12 ways of speeding up BASIC are of use to you. If you have any other suggestions for speeding up BASIC or anything to do with BASIC programming why not write a short article or send any suggestions for articles to me at WMJ Date System. I am always Looking for ideas.
Products
Downloadable Media
Image Gallery
Source Code
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.