Page 1 of 1

BASIC speed

Posted: Mon May 12, 2014 7:50 am
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.

Re: BASIC speed

Posted: Mon May 12, 2014 8:30 am
by poglad
Why don't you write a program to find out? ;)

Re: BASIC speed

Posted: Mon May 12, 2014 10:34 am
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.

Re: BASIC speed

Posted: Mon May 12, 2014 10:45 am
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

Re: BASIC speed

Posted: Mon May 12, 2014 10:58 am
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.

Re: BASIC speed

Posted: Mon May 12, 2014 10:58 am
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

Re: BASIC speed

Posted: Mon May 12, 2014 11:02 am
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.

Re: BASIC speed

Posted: Mon May 12, 2014 11:05 am
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.

Re: BASIC speed

Posted: Mon May 12, 2014 5:02 pm
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".