ZX81 BASIC performance

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
cpcoxygen
Posts: 1
Joined: Mon Oct 03, 2016 12:14 pm

ZX81 BASIC performance

Post by cpcoxygen »

I've recently received a ZX81 and having lots of fun with it. However I have a question about BASIC performance in comparision with a ZX Spectrum which I hope someone can shed light on.

I know the CPU is clocked at 3.25 instead of 3.5 MHz and that the CPU has to work harder to update the screen but I did a simple speed comparison and I found the ZX81 to be vastly slower even in FAST mode.

I typed this simple program:
10 for a=1 to 100
20 print a;
30 next a

The ZX Spectrum completed the above in about 1.8 seconds. The ZX81 was 36.4 seconds. Thinking this was due to the extra load the CPU has to work with to display screen content I changed to FAST mode. I expected the ZX81 to be behind but close to the Spectrum but instead I got a result of 10.7 seconds. About 6 times slower.

Surely in FAST mode the CPU wasn't under stress updating the screen? I know the RAM chips may be somewhat slower but surely not that much and the CPU is almost on par with the Spectrum? Was ZX81 BASIC not as streamlined as on the Spectrum?

I know this is not an conclusive test but could anyone shed any light on this? Thanks.
User avatar
Paul
Posts: 1511
Joined: Thu May 27, 2010 8:15 am
Location: Germanys west end

Re: ZX81 BASIC performance

Post by Paul »

In fact the ZX81 is stressed while printing in fast mode as well.
The spectrum has a fixed video ram.
There for no extra effort is needed when printing.
The ZX81 has a variable screen size and position.
When printing to the screen it needs to move the content of the ram around in order to find place to print at.
At least if memory is limited.
On a 16k ZX81 the problem should not occur.
kind regards Paul
In theory, there is no difference between theory and practice. But, in practice, there is.
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX81 BASIC performance

Post by 1024MAK »

PRINTing to the screen is slow on both machines. But a ZX81 with 3k bytes or less of RAM is even slower, as Paul explained.

In fact, some parts of the ZX81 BASIC ROM code (if run at the same CPU speed as a ZX Spectrum) are slightly faster. As the ZX Spectrum ROM code has more conditions in it.

So, for speed, don't write to the screen unless you have to. And try not to do any writing to the screen in any loops.

One thing to keep in mind when comparing different BASICs, is that the ROM is made up of machine code instructions for the CPU. Sinclair wanted maximum functionality with the most features that could be fitted in (and some). So the writers used space efficient code. Some of this was at the expense of speed... [ZX81 = 8k bytes, ZX Spectrum = 16k bytes, BBC B = nearly 32k bytes, MTX = 24k bytes etc...]

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
zsolt
Posts: 214
Joined: Wed Apr 20, 2011 11:43 am
Location: Fót, Hungary

Re: ZX81 BASIC performance

Post by zsolt »

Hi,

Some years ago, when i dealt with benchmark tests, i got same result - printing is very slow.
(and in '83 too - when i decided to learn the z80 mc programming :mrgreen: )
Paul wrote:The ZX81 has a variable screen size and position. When printing to the screen it needs to move the content of the ram around in order to find place to print at. At least if memory is limited. On a 16k ZX81 the problem should not occur.
It depends on the size of the variables area. If there is just one loop counter, then the time difference is not significant (see this little video), but...
if we run the next code (the "DIM"-line increases the variables area), then the time difference is more than 6% (16k: 37.8 sec vs. 1K:40.3 sec)

Code: Select all

 1 DIM A(100)
10 FOR I=1 TO 100
20 PRINT I;
30 NEXT I
Regards,
Zsolt
ZX81 (8K), ENTERPRISE 128, [ZX SPECTRUM (48K,+,+128K,+2,+2A), TS1000, TS1500, TS2068, Cambridge Z88, PRIMO A64 (red)]
User avatar
zsolt
Posts: 214
Joined: Wed Apr 20, 2011 11:43 am
Location: Fót, Hungary

Re: ZX81 BASIC performance

Post by zsolt »

Hi,
I ran a few more tests, and I think I've found the cause of problem above - the PRINT-FP routine is the bottleneck.
It is not by chance that this section has been completely rewritten for the speccy's rom.
the values are in seconds
the values are in seconds
Speed_tests.png (15.57 KiB) Viewed 5484 times
Regards,
Zsolt
ZX81 (8K), ENTERPRISE 128, [ZX SPECTRUM (48K,+,+128K,+2,+2A), TS1000, TS1500, TS2068, Cambridge Z88, PRIMO A64 (red)]
Post Reply