6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu May 09, 2024 6:26 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Mandelbrot Benchmarking
PostPosted: Thu Oct 05, 2023 4:02 pm 
Online
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1408
Location: Scotland
I decided to update my old Mandelbrot benchmark to the one I used recently (originally in VTL) to check my TinyBasic, then on a whim, I decided to make it work on the other BASICs I had to-hand.

It should work on most retro/8-bit BASIC systems with minimal changes and work over 16-bit signed integer BASICs to 4 or 5 byte floating point ones.

I put it all here:

https://projects.drogon.net/retro-basic ... andelbrot/

Cheers,

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 05, 2023 5:45 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
Nice thanks for sharing it - I'm thinking of following your lead and porting BBC BASIC to my system, then maybe I can give it a go!


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 05, 2023 8:59 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
Nice - thanks for writing up and sharing!

I wonder if there's something funny going on - I'm not 100% happy about the integer-mode output. Of course the problem might be my expectations!

Here's an owlet link for the Beeb running Basic 2
And here's the same thing but using integer arithmetic.
(In both cases, press the rocket button for a quick run.)

I'm suspicious of the shapes of the contours - posting this with a vague idea I might look into it tomorrow.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 05, 2023 9:44 pm 
Online
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1408
Location: Scotland
BigEd wrote:
I'm suspicious of the shapes of the contours - posting this with a vague idea I might look into it tomorrow.


Me too... I'll translate it to another integer only system tomorrow when I get some time and compare.

Thanks,

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 05, 2023 10:35 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
BigEd wrote:
Nice - thanks for writing up and sharing!

I wonder if there's something funny going on - I'm not 100% happy about the integer-mode output. Of course the problem might be my expectations!
...
I'm suspicious of the shapes of the contours - posting this with a vague idea I might look into it tomorrow.

I had a play with this. Firstly I tried using "DIV" instead of "/" in the floating point version, and the output was not the same. Debugging this revealed that on line 220 the fraction from dividing by F% was affecting the result - i.e. in the integer version, this bit at least was benefiting from "/" being floating point division. So to get a truly integer execution in BBC BASIC, I think you do need to carefully change all the "/" to "DIV", or at least this one!

The real problem however is with the bounds check on lines 230-240:

Code:
230A%=T%: P%=A%/F%:Q%=B%/F%
240IF ((P%*P%)+(Q%*Q%))>=5 GOTO 280

P% and Q% suffer badly from rounding here, as you're dividing by the fixed point factor. You can use floating point for P and Q, or better, do the comparison in the fixed point space:

Code:
230A%=T%
240IF ((A%*A% DIV F%)+(B%*B% DIV F%))>=5*F% GOTO 280

This may suffer different problems if it ends up overflowing the maximum integer width - 16 bits is pretty narrow - I haven't thought much about what the worst-case inputs would be though!

It seems to work pretty well:
https://bbcmic.ro/#%7B%22v%22%3A1%2C%22 ... %5Cn%22%7D


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 06, 2023 7:07 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
Oh, well done, that does look a lot better!


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 06, 2023 7:36 am 
Online
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1408
Location: Scotland
BigEd wrote:
Oh, well done, that does look a lot better!


Also, as an aside, interesting to note than even when presented with all integer variables, BBC Basic still does floating point operations if you're not careful...

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 06, 2023 7:53 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
Yes... it does seem to make it a bit more difficult to experiment with the implications of different word sizes.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 06, 2023 9:43 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1928
Location: Sacramento, CA, USA
gfoot wrote:
The real problem however is with the bounds check on lines 230-240:

Code:
230A%=T%: P%=A%/F%:Q%=B%/F%
240IF ((P%*P%)+(Q%*Q%))>=5 GOTO 280

P% and Q% suffer badly from rounding here, as you're dividing by the fixed point factor. You can use floating point for P and Q, or better, do the comparison in the fixed point space:

Code:
230A%=T%
240IF ((A%*A% DIV F%)+(B%*B% DIV F%))>=5*F% GOTO 280

This may suffer different problems if it ends up overflowing the maximum integer width - 16 bits is pretty narrow - I haven't thought much about what the worst-case inputs would be though!

WOZ BASIC errored out almost immediately with your modification, but was able to render a less accurate version of Gordon's original in about 696 seconds @ 1 MHz:
Code:
  100 REM PR#3 FROM > PROMPT FIRST!
  105 PRINT "MANDELBROT - WOZ BASIC"
  110 PRINT "START"
  130 DIM Z$(17):Z$=".:,;-=+^/%&S$X#@ "
  140 F=50
  150 FOR Y=-12 TO 12
  160 FOR X=-49 TO 29
  170 C=X*229/100
  180 D=Y*416/100
  190 A=C:B=D:I=1
  200 Q=B/F:S=B-Q*F
  210 T=(A*A-B*B)/F+C
  220 B=2*(A*Q+A*S/F)+D
  230 A=T:P=A/F:Q=B/F
  240 IF P*P+Q*Q>4 THEN 280
  250 I=I+1: IF I<17 THEN 200
  280 PRINT Z$(I,I);: NEXT X
  300 PRINT : NEXT Y
  330 PRINT "FINISHED";
  350 END

Attachment:
MAND_WOZ.PNG
MAND_WOZ.PNG [ 6.59 KiB | Viewed 4213 times ]

Applesoft renders a much better image, but takes about 860 seconds @ 1 MHz:
Code:
100  REM PR#3 FROM ] PROMPT FIRST!
105  PRINT "MANDELBROT - APPLESOFT"
110  PRINT "START"
130 Z$ = ".:,;-=+^/%&S$X#@ "
140 F = 50
150  FOR Y =  - 12 TO 12
160  FOR X =  - 49 TO 29
170 C = X * 229 / 100
180 D = Y * 416 / 100
190 A = C:B = D:I = 1
200 Q = B / F:S = B - Q * F
210 T = (A * A - B * B) / F + C
220 B = 2 * (A * Q + A * S / F) + D
230 A = T:P = A / F:Q = B / F
240  IF P * P + Q * Q > 4 THEN 280
250 I = I + 1: IF I < 17 THEN 200
280  PRINT  MID$ (Z$,I,1);: NEXT X
300  PRINT : NEXT Y
330  PRINT "FINISHED";
350  END


Attachment:
MAND_A2+.PNG
MAND_A2+.PNG [ 6.6 KiB | Viewed 4210 times ]

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: