★ APPLICATIONS ★ DIVERS ★ Profiler ★![]() |
| Profiler (Computing With the Amstrad) | Applications Divers |
JOHN RAWLINSON offers a neat way of shifting into top gear on your CPC SOONER or later one problem that faces everyone who writes computer programs is how to make a program run faster. Obvious solutions are to rewrite the program in machine code, or use a compiler to do this for you. However 90 per cent of the time a program takes to execute will usually be spent in a small section. Rewriting this part of the program in a more efficient way will often give the required improvement in speed. This leaves the problem of finding where a program spends most of its time. The easy way to do this is with a program called a profiler and this article describes one which can be used with Basic programs on the CPC range. It comes in two parts, a small machine code program which sets up two new RSX bar commands, and a chunk of Basic which is added to the program being profiled in order to display the results. Program I enables a fast ticker -1/300th of a second - event. It looks for the line the Basic interpreter is currently handling 300 times a second and increments a two byte count for that particular line number. The machine code for this program is contained in the data statements. The program should be typed in and then saved. When it is run two new bar commands will be set up - |START and |STOP. |START clears the count for all lines to zero and sets off the fast ticker event, while |STOP switches off the event and halts the line incrementing. The code works by looking at a Basic interpreter variable - stored in location &AE36 on a 464, or &AE1D on a 664 or 6128 - which contains the start address of the current Basic line. It is then fairly simple to look a couple of bytes further along the line and discover its number. Program II is the Basic section of the profiler, and it should be typed in and saved in Ascii form using: SAVE"profile2",AThe procedure for profiling a program, is as follows. Firstly if the one you wish to profile contains a SYMBOL AFTER command REM it out along with any MEMORY command that attempts to raise HIMEM above that set by Program I. Then in direct mode type in the SYMBOL AFTER command you have just removed and run Program I.Next the program to be profiled must be loaded and renumbered if necessary - (see later) and then Program II MERGEd with it. A |START command should then be added to the beginning and a |STOP command entered at the point where it finishes. Inserting the |STOP command is not too critical as the program can be halted by pressing Escape before this command is met. Finally run the main program and when the |STOP takes effect or you press Escape type RUN 30000 and this will execute the results section of the profiler. The first thing you will see is a menu allowing you to select one of three options - a display of the same information either by individual line numbers, groups of 10 line numbers or groups of 100. The information presented is the number of ticks for that line or group and the percentage of the total time spent executing the program that was expended on the line or group. A tick is recorded each time the line is seen by an event. As set up the program can only handle line numbers in the range 0 to 1000 which means that your program must be renumbered to fit into this range before the profiler is used on it. The variable nl in line 30060 sets the number of lines the profiler displays results for. This should be changed to a value between 100 and 1000 in steps of 100 depending on the size of your program. Keeping it small will make the analysis process quicker. The use of the fast ticker event means that the profiler will spot all but the simplest lines. However it also means that the two byte count may overflow if the profiling session lasts more than 30 minutes. The programs time range can be extended by using the 50Hz frame sync, event instead. This can be done by making the following changes to Program I: 90 IF i < > 23438 THEN PRINT"Check sue error !"':ENDWhen all the results have been displayed pressing any key will return you to the menu. |
| ![]() |
|