BBC BASIC timing comparison

chat about arc/risc pc gaming & RISC OS software here (NOT the core OS!)Related forum: adventures


Post Reply
User avatar
Richard Russell
Posts: 877
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

BBC BASIC timing comparison

Post by Richard Russell » Sat Jun 08, 2019 11:44 am

There's an ongoing discussion about interpreter timings at the Raspberry Pi forums and I speculated there that Sophie's ARM interpreter (coded in assembler) almost certainly runs considerably faster than mine (compiled from C) on the same hardware. If somebody has a Raspberry Pi 3B (not +) with RISC OS, I would appreciate it if they could run the following program in BASIC 5 and post the result:

Code: Select all

      TIME = 0
      FOR I% = 1 TO 10000000
      NEXT
      PRINT TIME
(that's an empty FOR loop with 10 million iterations, which is admittedly a rather artificial benchmark). On my RPi 3B running Raspbian Stretch and BBC BASIC for SDL 2.0 v1.03a I get an average of 193 centiseconds over several runs.

sparkyhall
Posts: 21
Joined: Sun Feb 17, 2019 8:29 pm
Contact:

Re: BBC BASIC timing comparison

Post by sparkyhall » Sat Jun 08, 2019 12:48 pm

I consistently get a time of 35 centiseconds, I'm surprised it's that much faster than yours?

This is on a Pi3B and RiscOS 5.24.

User avatar
Richard Russell
Posts: 877
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC timing comparison

Post by Richard Russell » Sat Jun 08, 2019 1:34 pm

sparkyhall wrote:
Sat Jun 08, 2019 12:48 pm
I consistently get a time of 35 centiseconds, I'm surprised it's that much faster than yours?
I'm not, Sophie's BASICs have always had a reputation for speed. Even my assembler versions have never come close to hers, and of course when compiled from C there's an even bigger overhead. It's also significant that Brandy BASIC, which is compiled from C, is a good bit faster than mine (although a fair comparison is difficult because it's not a 'pure' interpreter and employs some 'pre processing' tricks).

An additional factor is the number of extra numeric data types that my interpreters support. With only 32-bit integers and 40-bit floats to contend with I wouldn't be surprised if Sophie's code effectively has two different implementations of the NEXT statement. That's an optimisation which would be over-the-top in my interpreters, with 8-bit, 32-bit and 64-bit integers, plus 64-bit and 80-bit floats to deal with (any of which can be used as the loop variable).

Thanks for the feedback anyway, I'll report back to the Raspberry Pi forum.
Last edited by Richard Russell on Sat Jun 08, 2019 1:35 pm, edited 1 time in total.

Soruk
Posts: 413
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC timing comparison

Post by Soruk » Wed Jun 12, 2019 1:23 pm

Just for comparison, Matrix Brandy on RasPi 2 (don't have my Pi3+ handy from remote), gives 85.

User avatar
Richard Russell
Posts: 877
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC timing comparison

Post by Richard Russell » Wed Jun 12, 2019 2:39 pm

Soruk wrote:
Wed Jun 12, 2019 1:23 pm
Just for comparison, Matrix Brandy on RasPi 2 (don't have my Pi3+ handy from remote), gives 85.
Thanks. Given that when (the original) Brandy was written the challenge was to make it as fast as Sophie's assembler version - through the use of 'tricks' to overcome the inherent overhead of being compiled from C - I expect it would match (or come close to) the quoted 35 when run on a RPi 3. I must say I have never been tempted to employ those kinds of tricks in 'my' BASICs, because they tend to break things like self-modifying code or on-the-fly code creation at run time. Those aren't things that I often make use of, nor would I encourage, but occasionally they are invaluable (my OOP library 'classlib.bbc' couldn't work without generating BASIC code on-the-fly).

I have no doubt that the C version of BBC BASIC for SDL 2.0 could be made significantly faster if it received the attention of a competent C programmer, which I am not. Mindlessly translating x86 assembly language to C, almost on an instruction-by-instruction basis, was never going to result in efficient code! But it was the only way I could ever have ported my interpreter to platforms other than 32-bit Windows, so I'm pleased that it works at all - even if it's slow.

On 'modern' platforms interpreter speed is rarely an issue anyway; the bottlenecks are more commonly in graphics rendering or file access - or just waiting for the user to respond. Unfortunately that's not so often the case with the Raspberry Pi, since it's such a slow machine by current standards (although not considering its price of course).

sirbod
Posts: 995
Joined: Mon Apr 09, 2012 8:44 am
Location: Essex
Contact:

Re: BBC BASIC timing comparison

Post by sirbod » Fri Jun 14, 2019 2:51 pm

I also get 35 on a Pi3 and just for a laugh I tried it under ADFFS, which runs the 26bit SA version of BASIC under the JIT and got 43.

User avatar
Richard Russell
Posts: 877
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC timing comparison

Post by Richard Russell » Fri Jun 14, 2019 4:38 pm

sirbod wrote:
Fri Jun 14, 2019 2:51 pm
I also get 35 on a Pi3 and just for a laugh I tried it under ADFFS, which runs the 26bit SA version of BASIC under the JIT and got 43.
A completely unfair comparison, of course, but on this Windows 10 laptop I get 22 cs, illustrating both the slowness of the RPi and how little interpreter speed typically matters on a modern PC.

Soruk
Posts: 413
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC timing comparison

Post by Soruk » Mon Jun 17, 2019 5:15 am

Richard Russell wrote:
Fri Jun 14, 2019 4:38 pm
sirbod wrote:
Fri Jun 14, 2019 2:51 pm
I also get 35 on a Pi3 and just for a laugh I tried it under ADFFS, which runs the 26bit SA version of BASIC under the JIT and got 43.
A completely unfair comparison, of course, but on this Windows 10 laptop I get 22 cs, illustrating both the slowness of the RPi and how little interpreter speed typically matters on a modern PC.
Matrix Brandy on a Core i7 laptop under Windows 10 scored 5 (my work machine, I'll update later with Escape disabled!).

Edit: This has also highlighted a performance problem if I disable Escape with *FX200,0 - it was still checking for the escape key then discarding the result! Having to do three SDL calls for an INKEY(-ve) call, and ESCAPE checking is done by internally calling INKEY(-113), makes it quite expensive. On my CentOS virtual machine running on my AMD FX8350 VM host, under SDL I was getting at best 11, with this fix and disabling Escape with *FX200 I am now getting 4. With a text-mode build I can get 3.

Edit 2: My Raspberry Pi 3+ gets 53 with a text-mode build, 56 with an SDL build.
Last edited by Soruk on Mon Jun 17, 2019 6:38 am, edited 4 times in total.

User avatar
Richard Russell
Posts: 877
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC timing comparison

Post by Richard Russell » Mon Jun 17, 2019 8:15 am

Soruk wrote:
Mon Jun 17, 2019 5:15 am
ESCAPE checking is done by internally calling INKEY(-113)
I would not expect ESCape to be checked asynchronously (i.e. polled) like that: it's expensive, on some platforms it might detect the key being pressed even if BASIC doesn't have keyboard focus (for example using GetAsyncKeyState in Windows) and it might miss the key being pressed for only a very short time. There are also potential accessibility issues if used with alternative 'non keyboard' input devices.

In all my implementations of BBC BASIC, ESCape detection has always used the conventional synchronous keypress mechanism, and as that is (usually) conveyed to the application by an event or callback, not by polling, there should be little or no overhead. In the case of BBCSDL the keypress event handler sets a flag in memory which is polled by the interpreter, which is very fast.
Last edited by Richard Russell on Mon Jun 17, 2019 8:16 am, edited 1 time in total.

Soruk
Posts: 413
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC timing comparison

Post by Soruk » Mon Jun 17, 2019 12:00 pm

Richard Russell wrote:
Mon Jun 17, 2019 8:15 am
Soruk wrote:
Mon Jun 17, 2019 5:15 am
ESCAPE checking is done by internally calling INKEY(-113)
I would not expect ESCape to be checked asynchronously.....
Taking this over to the Matrix Brandy thread.....

Post Reply