Recently, my old Benchmark thread saw some activity so I thought I'd try some of the old tricks we used to do to make BASIC programs run faster, as we did back in the day.
But I want to say firstly that this is not too fair - part of the point of my original Mandelbrot benchmark was to keep the source code identical over all platforms, so this really is cheating and I have, perhaps unfairly, taken advantage of some of BBC Basics features (compared to MS Basics, anyway)
I removed all un-needed spaces and joined lines together as much as I could. I used integer% variables where possible and changed all 2-letter variable names into single letters. The resulting code is somewhat hard on the eyes, however it did run faster. Fast enough to make a difference? Yes . Was it worth it? Who knows.
(FYI: Integers in BBC Basic are 32-bits wide and are treated as Integers where possible, but in particular, single letter Integer variables are stored in fixed memory locations to make them ever faster)
My original one runs in 48.2 seconds on my 16Mhz 65C02 system (actually an '816 in emulation mode) running BBC Basic4.
My tweaked version now runs in 39.4 seconds, so almost 10 seconds better. That was a far better improvement than fiddling with IO to try to cater for the potential slow-downs caused by the actual print routines.
So there you go. Draw your own conclusions.... and someone else can run it under MS Basic/EhBASIC as I really don't care for that old BASIC any more. Give me a modern BASIC from 1981
Code:
>*ftp get mandel.2.txt
>*exec mandel.2.txt
>100REM A BASIC, ASCII MANDELBROT
>110REM
>120REM This implementation copyright (c) 2019-2021, Gordon Henderson
>130REM
>140REM Permission to use/abuse anywhere for any purpose granted, but
>150REM it comes with no warranty whatsoever. Good luck!
>160REM
>170C$=".,'~=+:;[/<&?oxOX# " : REM 'Pallet' Lightest to darkest...
>180B%=1 : REM Set to 0 if your MID$() indexes from 0.
>190L%=LEN(C$)
>200M=4
>210S=-2.0
>220T=1.25
>230P=2.5
>240Q=-2.5
>250W%=64
>260H%=48
>270J=P/W%
>280U=Q/H%
>290Q%=TIME
>300FORY%=0TOH%:R=Y%*U+T:FORX%=0TOW%:V=X%*J+S:D=0:E=0:A%=B%
>370G=D*D:H=E*E:IFA%>L% GOTO460
>400IF(G+H)>M GOTO460
>410Z=G-H+V:E=(D+D)*E+R:D=Z:A%=A%+1:GOTO370
>460PRINT MID$(C$,A%-B%,1);
>470NEXT:PRINT:NEXT
>500PRINT
>510PRINT (TIME - Q%) / 100
>520END
>RUN
............,,,,,,,,,,,,,,'''''''''''''''''''''''''',,,,,,,,,,,,,
...........,,,,,,,,,,,''''''''''''''''''''''''''''''''',,,,,,,,,,
..........,,,,,,,,,'''''''''''''''''''''''~~~~===~~~~''''',,,,,,,
.........,,,,,,,,'''''''''''''''''''''~~~~~~=+[&+==~~~~~''''',,,,
........,,,,,,,'''''''''''''''''''''~~~~~~~==+: ;+++~~~~~~''''',,
.......,,,,,,'''''''''''''''''''''~~~~~~~~===+:[ / [+~~~~~~''''''
......,,,,,,''''''''''''''''''''~~~~~~~~~===+:;/?o[:+==~~~~~'''''
......,,,,''''''''''''''''''''~~~~~~~~~====+:O/x <;:+==~~~~~~'''
.....,,,,''''''''''''''''''''~~~~~~~~~===++:# X/+====~~~~'''
.....,,,'''''''''''''''''''~~~~~~~~~==++++:;/X [:++====~~~''
....,,,'''''''''''''''''''~~~~~~~~==+++:::;[/ X/;:+++++==~~'
....,,''''''''''''''''''~~~~~~~===+[<&x[[? <&x o&//<;:::[[=~~
...,,'''''''''''''''''~~~~~~=====+:; &O /[</&/:=~
...,'''''''''''''''''~~~========++:;< x :=~
..,,'''''''''''''''~~=========+++:;/<O ;+==
..,'''''''''''''~~~=========++++:< ## X<;:+=
..''''''''''~~~~==:/++++++++::::;/x [;:=
.,''''''~~~~~~===+:X[;:;; ;;::;;[ o/=
.,''''~~~~~~~===++;<xXo<<X &<[[[/ X:+
.'''~~~~~~~=====+::[& <<& /:=
.'~~~~~~~~=====+::;/? oO :=
.'~~~~~~~====++/;[/o [+=
.~~~~~~=++++::;/???X #:+=
.==++:/::+:;;[[o :+==
&[:+==
.==++:/::+:;;[[o :+==
.~~~~~~=++++::;/???X #:+=
.'~~~~~~~====++/;[/o [+=
.'~~~~~~~~=====+::;/? oO :=
.'''~~~~~~~=====+::[& <<& /:=
.,''''~~~~~~~===++;<xXo<<X &<[[[/ X:+
.,''''''~~~~~~===+:X[;:;; ;;::;;[ o/=
..''''''''''~~~~==:/++++++++::::;/x [;:=
..,'''''''''''''~~~=========++++:< ## X<;:+=
..,,'''''''''''''''~~=========+++:;/<O ;+==
...,'''''''''''''''''~~~========++:;< x :=~
...,,'''''''''''''''''~~~~~~=====+:; &O /[</&/:=~
....,,''''''''''''''''''~~~~~~~===+[<&x[[? <&x o&//<;:::[[=~~
....,,,'''''''''''''''''''~~~~~~~~==+++:::;[/ X/;:+++++==~~'
.....,,,'''''''''''''''''''~~~~~~~~~==++++:;/X [:++====~~~''
.....,,,,''''''''''''''''''''~~~~~~~~~===++:# X/+====~~~~'''
......,,,,''''''''''''''''''''~~~~~~~~~====+:O/x <;:+==~~~~~~'''
......,,,,,,''''''''''''''''''''~~~~~~~~~===+:;/?o[:+==~~~~~'''''
.......,,,,,,'''''''''''''''''''''~~~~~~~~===+:[ / [+~~~~~~''''''
........,,,,,,,'''''''''''''''''''''~~~~~~~==+: ;+++~~~~~~''''',,
.........,,,,,,,,'''''''''''''''''''''~~~~~~=+[&+==~~~~~''''',,,,
..........,,,,,,,,,'''''''''''''''''''''''~~~~===~~~~''''',,,,,,,
...........,,,,,,,,,,,''''''''''''''''''''''''''''''''',,,,,,,,,,
............,,,,,,,,,,,,,,'''''''''''''''''''''''''',,,,,,,,,,,,,
39.37
-Gordon
Ps. I have just tried it under EhBASIC - which doesn't seem to support integer variables with the % symbol... (huh?) and CBM2 BASIC can't handle integer variables in FOR loops by the looks of it....