BASIC speed

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

BASIC speed

Post by Shaun_B »

I know it's not going to make much difference overall, but is it faster in ZX81 BASIC to use things like LET X=PI/PI, or for speed purposes, should I just say LET X=1?

Regards,

Shaun.
poglad
Posts: 133
Joined: Mon Mar 24, 2014 3:11 pm
Location: Aberdeen, Scotland

Re: BASIC speed

Post by poglad »

Why don't you write a program to find out? ;)
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: BASIC speed

Post by Shaun_B »

How do I accurately time it then? For instance, I can wait for the raster on the Commodore 64, or simply say TI$="000000" at the start of the program. What's the equivalent on the ZX81?


Regards,

Shaun.
poglad
Posts: 133
Joined: Mon Mar 24, 2014 3:11 pm
Location: Aberdeen, Scotland

Re: BASIC speed

Post by poglad »

You can do almost the same thing, there's a system variable called FRAMES. The ZX81 manual is online, and I think there's even a timing example in there. EDIT: Okay, didn't see a timing example, but FRAMES is at 16436 and 16437. So you can say LET FRAMES=PEEK 16436+256*PEEK 16437. According to the manual, it decreases by 1 every frame (i.e. every 50th of a second), so you could sample it at the start, do your bit of code inside a loop say 100 times, then sample it at the end. Then (START-END)/50 will give you the number of seconds elapsed.

By the way, if you're not coding to fit in 1K, what's with all the PI/PI stuff anyway? There's really no point unless memory is at a premium! :D
poglad
Posts: 133
Joined: Mon Mar 24, 2014 3:11 pm
Location: Aberdeen, Scotland

Re: BASIC speed

Post by poglad »

I should add, obviously the value of FRAMES will eventually wrap around, which might give you a weird negative result if your program starts just before it wraps, and ends just after. You can either just run it again if you get that, or you could do a POKE 16437,255 at the start to make sure it's nowhere near wrapping. I wouldn't bother, personally.

I just found the following page http://forum.tlienhard.com/ts1000/www.t ... sembly.htm which shows EXACTLY what I was talking about in my last post, haha! Honestly, I didn't see it until after I posted it! He doesn't bother dividing the result (actually his computer is the US model, so you'd need to divide it by 60), he just displays the elapsed frame count. You basically put your test code at line 30.

Not sure I understand his results comparing different machines, but it should definitely be reliable for comparing different coding forms on the same machine.
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: BASIC speed

Post by 1024MAK »

Shaun_B wrote:I know it's not going to make much difference overall, but is it faster in ZX81 BASIC to use things like LET X=PI/PI, or for speed purposes, should I just say LET X=1?
LET X=1 is faster.

There is a whole thread on here somewhere about the quickest way, or the most memory frugal way.

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.
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: BASIC speed

Post by Shaun_B »

poglad wrote:By the way, if you're not coding to fit in 1K, what's with all the PI/PI stuff anyway? There's really no point unless memory is at a premium! :D
It was habit more than thinking about memory efficiency. I used to program the ZX81 back in the day, like Bruce Willis, these habits die hard.

Regards,

Shaun.
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: BASIC speed

Post by Shaun_B »

1024MAK wrote:
Shaun_B wrote:I know it's not going to make much difference overall, but is it faster in ZX81 BASIC to use things like LET X=PI/PI, or for speed purposes, should I just say LET X=1?
LET X=1 is faster.

There is a whole thread on here somewhere about the quickest way, or the most memory frugal way.

Mark
I used the search for BASIC speed and nothing came up - in other words, I didn't look hard enough :-\

Regards,

Shaun.
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: BASIC speed

Post by PokeMon »

1024MAK wrote:LET X=1 is faster.
Yes - sure.
But it is shorter in program bytes to use PI/PI which occupies 3 bytes while representation of "1" would occupy 7 bytes.
Same would be to use PI-PI for getting the value "0".
Post Reply