home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
utility
/
pbaseiv.zip
/
P4MSC002.TIP
< prev
next >
Wrap
Text File
|
1991-12-16
|
3KB
|
77 lines
To time BASIC routines, I wrote PROFILE.BAS [see listing].
The program runs a profiling subroutine that times up to 100
elapsed repeats of any instruction.
To profile a program, copy the subroutine (lines 9000
through 9250) to your own code. (Lines 1100-1999 are
included here only to demonstrate the profiler.) Near the
beginning of your program, dimension an array PFACCUM!(100),
set PFPOINT% to 0, and execute GOSUB 9000 as PROFILE.BAS
does at lines 1100 through 1200. Then, at strategic
locations, set PFPOINT% to a number between 1 and 99, and
execute GOSUB 9000. (See lines 1250 through 1600 for
examples of these steps.) The profile numbers do not have to
be in sequence.
To display results for profiled points, set PFPOINT% to 100
or higher, and execute GOSUB 9000 as in line 1900. Once you
have done that, any future calls to the profiler subroutine
will be ignored.
Precision is limited to the smallest fractions of seconds
that TIMER provides. Short sequences may run so fast that
they won't show in the report. Therefore, to profile a
single statement, you may have to insert it into a FOR loop
that cycles at least 1000 times.
Gil Gagnon
Mississauga, Ontario, Canada
Editor's note: Use the profiler's report to find where your
code spends the bulk of its time. By optimizing the most
heavily traveled sections, you'll gain the greatest speed
advantage with the least amount of work.
Because PC clocks are imprecise, you may receive different
results for the same program profiled twice in succession.
For better accuracy, profile your code three or more times
and average the reported values.
PROFILE.BAS (Use Alt-F to extract to a file)
---- BEGIN LISTING ----
1100 DIM PFACCUM!(100)
1200 PFPOINT% = 0: GOSUB 9000
1250 PRINT "Test loop #1"
1300 FOR N = 1 TO 10000 : NEXT N
1400 PFPOINT% = 1: GOSUB 9000
1450 PRINT "Test loop #2"
1500 FOR N = 1 TO 5000 : NEXT N
1600 PFPOINT% = 2: GOSUB 9000
1900 PFPOINT% = 100: GOSUB 9000
1999 END
9000 IF PFFIRST% = 1 THEN GOTO 9050
9010 PFFIRST% = 1
9020 PFEND% = 0
9030 PFTIMELAST! = TIMER
9040 PFLBL$ = "Elapsed time for point"
9050 IF PFEND% <> 0 THEN GOTO 9250
9060 PFTIME! = TIMER
9070 IF PFPOINT% > 99 THEN PFPOINT% = 99
9080 PFACCUM!(PFPOINT%) = PFACCUM!(PFPOINT%) + PFTIME! - PFTIMELAST!
9090 PFTIMELAST! = PFTIME!
9100 IF PFPOINT% <> 99 THEN GOTO 9250
9110 PFEND% = 1
9120 FOR PFPOINT% = 1 TO 100
9130 IF PFACCUM!(PFPOINT%) = 0 GOTO 9140
9135 PRINT PFLBL$; PFPOINT%; ":"; PFACCUM!(PFPOINT%)
9140 NEXT PFPOINT%
9250 RETURN
---- END LISTING ----
Title: BASIC Profiles
Category: MSC
Issue date: Apr 1991
Editor: Tom Swan
Supplementary files: NONE