A simple MSX Basic question

Página 1/3
| 2 | 3

Por Josb

Master (206)

imagem de Josb

03-11-2018, 11:15

hello,

I would like to know what expression is faster in MSX-BASIC

IF BA>0 THEN XB=XB+IB

or

XB=XB-IB*(BA>0)

Obviously, BA is a flag to know if bullet is fired and XB,YB its coordinates. So, my real question is to know whether it is worth to use the second expression bearing BA is not always >0 in mind.

Thank you

Entrar ou registrar-se para comentar

Por theNestruo

Champion (414)

imagem de theNestruo

03-11-2018, 11:58

IF is faster, specially if the condition is not met.
Check this quick example: https://msxpen.com/codes/-LQOD2EH4x_R66vgbbTP

Por Josb

Master (206)

imagem de Josb

03-11-2018, 12:13

Thanks Smile

I don't really know how MSX Basic works inside. I though that the second expression would spend less memory making code faster at the end.

by the way, good idea to use MSXPen.

Por theNestruo

Champion (414)

imagem de theNestruo

03-11-2018, 12:32

I did some research when coding Pérez the Mouse for Konamito's MSX-BASIC contest.
Particularly, I found something really particular about expressions: A=B*5+10 is faster that A=10+5*B. My guess is that in the first expression MSX-BASIC can evaluate things as they come, but in the second one it has to "stack" the 10 to compute the other operand, then "stack" the 5 to look for the value of the variable, and then evaluates the expression.
Most of the optimization tricks were explained (in Spanish only) in the readme file distributed with the game. Maybe you can have a look at it to get some optimization ideas!

Por Grauw

Ascended (10710)

imagem de Grauw

03-11-2018, 12:39

You can time it yourself, right?

10 DEFINT A-Z
20 XB = 0 : IB = 2 : BA = 1
30 TIME = 0
40 FOR I = 0 TO 1000
50 XB = XB - IB * (BA > 0)
60 NEXT
60 PRINT TIME

Results for the turboR (R800 turbo mode):

  • For the IF I get 33 if BA = 0, and 53 if BA = 1.
  • For the multiplication I get 56 if BA = 0, and 59 if BA = 1.

Depending on the video refresh frequency, one TIME tick is either 1/50th or 1/60th of a second. In this case, it’s 1/60th.

Por Josb

Master (206)

imagem de Josb

03-11-2018, 12:50

I don't know whether Konamito will launch the contest this year or not, but I would like to be ready. I'm testing some codes to make something harder than other years. That is the reason of my question.

theNestruo wrote:

Most of the optimization tricks were explained (in Spanish only) in the readme file distributed with the game. Maybe you can have a look at it to get some optimization ideas!

Yes, I will do it.

I remember that there are some tricks as calling variable at the beginning of the code for hastening it, but I am not able to remind where I have read it.
Smile

Por Josb

Master (206)

imagem de Josb

03-11-2018, 12:48

@Grauw: Thanks for your answer

Actually I'm looking for little tricks to make MSX Basic faster. One of them that I have found is to change this piece of code

IF A=7 AND B=8 THEN ...

for this one

IF A=7 THEN IF B=8 THEN ...

Noting that A is the variable less feasible to be changed

Por gdx

Enlighted (6112)

imagem de gdx

03-11-2018, 13:32

It is multiplication (and division) that takes time in the example above.

And the difference between

IF A=7 AND B=8 THEN ...

and

IF A=7 THEN IF B=8 THEN ...

depends on the frequency A=7 or B=8 to be true. If A=7 most of the time, I think the second method will be slower. You have to put the least often true condition at first in this cas.

Por Josb

Master (206)

imagem de Josb

03-11-2018, 13:32

That is what meant Smile

Por Josb

Master (206)

imagem de Josb

04-11-2018, 11:38

theNestruo wrote:

Most of the optimization tricks were explained (in Spanish only) in the readme file distributed with the game. Maybe you can have a look at it to get some optimization ideas!

Sorry, I am not able to get the readme file you said. The only web I could download the game was this https://msxgamesworld.com/gamecard.php?id=3178 where the available .zip file hasn't any readme. Maybe it would be a good idea to upload in this threat if you don't mind.

Edit: Another idea to get faster is not use arrays :)
https://msxpen.com/?code=-LQTII3Ya4oH1HJ8Xd_B

Por theNestruo

Champion (414)

imagem de theNestruo

04-11-2018, 11:48

Is the zip file you are downloading named "Perez the Mouse (theNestruo, 2011).zip" or "Perez the Mouse (theNestruo, 2011) (v1.0).zip"?
The first one is under the "View more options" big button near the top of the page > "download now". This is the zip file that contains "source.sp.html".
The second zip file (the one that ends with "(v1.0)" is scrolling down, under the "miscellaneous" section, and does not contain source.sp.html".

Anyway, I've uploaded the file to my GitHubGist (source.sp.html)) so it can be downloaded more easily :)

Página 1/3
| 2 | 3