I made a few changes to the CHRGET routine in EhBasic and found some interesting timing changes. I'm using Bill O's Mandelbrot program from an earlier post. I've added a couple CALL statements which reset and display my benchmark counter (part of my Monitor/BIOS). The stock CHRGET routine results in a timing of 113.74 seconds to compete one run of the Mandelbrot. BASIC program:
Code:
5 CALL 65328
10 MX=20
20 LET C$=" .,'~!^:;[/<&?oxOX# "
30 FOR Y=-19 TO 19
40 FOR X=-49 TO 30
50 CR=X/30
70 CI=Y/15
80 ZR = CR
90 ZI = CI
95 CO = 1
100 ZM = ZR*ZR
105 ZN = ZI*ZI
107 ZL = ZM+ZN
110 IF ZL>4 THEN GOTO 170
120 ZJ=ZM-ZN+CR
130 ZI=ZR*ZI*2+CI
140 ZR=ZJ
150 CO=CO+1
160 IF CO<MX THEN GOTO 100
170 PRINT MID$(C$,1+COUNT,1);
180 NEXT X
185 PRINT ""
190 NEXT Y
195 CALL 57371
200 GOTO 5
First, I moved the CMP #' ' space to the top after the LDA, like this:
Code:
LAB_GBYT
LDA (Bpntrl) ; get byte to scan (addr set by call routine)
CMP #' ' ; compare with " "
BEQ LAB_IGBY ; if " " go do next
CMP #TK_ELSE ; compare with the token for ELSE
BEQ LAB_2D05 ; exit if ELSE, not numeric, carry set
CMP #':' ; compare with ":"
BCS LAB_2D05 ; exit if >= ":", not numeric, carry set
The timing changed to 114.90 seconds, over a second longer per run. Next, I changed to:
Code:
LAB_GBYT
LDA (Bpntrl) ; get byte to scan (addr set by call routine)
CMP #TK_ELSE ; compare with the token for ELSE
BEQ LAB_2D05 ; exit if ELSE, not numeric, carry set
CMP #' ' ; compare with " "
BEQ LAB_IGBY ; if " " go do next
CMP #':' ; compare with ":"
BCS LAB_2D05 ; exit if >= ":", not numeric, carry set
The timing actually got worse, at 115.06 seconds! So I put it back to the original code. I then tried Mike's change to the lower section of code:
Quote:
LAB_GBYT
LDA (Bpntrl) ; get byte to scan (addr set by call routine)
CMP #TK_ELSE ; compare with the token for ELSE
BEQ LAB_2D05 ; exit if ELSE, not numeric, carry set
CMP #':' ; compare with ":"
BCS LAB_2D05 ; exit if >= ":", not numeric, carry set
CMP #' ' ; compare with " "
BEQ LAB_IGBY ; if " " go do next
; SEC ; set carry for SBC
; SBC #'0' ; subtract "0"
; SEC ; set carry for SBC
; SBC #$D0 ; subtract -"0"
; clear carry if byte = "0"-"9"
; Change suggested by Mike Barry to replace above
EOR #'0' ; convert to binary
CMP #10 ; clear carry if decimal digit
EOR #'0' ; convert back to ASCII
This resulted in a timing of 113.54 seconds, a savings of 200 milliseconds per run. Nice!