Jump to content
IGNORED

if-thens: faster with or without a skipping goto?


Random Terrain

Recommended Posts

I probably asked something like this before, but I can't find it. Which version below is faster or better or both?

_

   if _Sound0 then goto __Skip_Joy0

   if joy0fire then _Sound0 = 1 : _Chan0_Duration = 15

   if joy0up then _Sound0 = 2 : _Chan0_Duration = 30 : _V0 = 12

   if joy0down then _Sound0 = 3 : _Chan0_Duration = 32 : _F0 = 31

   if joy0left then _Sound0 = 4 : _Chan0_Duration = 32 : _V0 = 12 : _F0 = 31

   if joy0right then _Sound0 = 5 : _Chan0_Duration = 32 : _C0 = 4 : _V0 = 12 : _F0 = 31

__Skip_Joy0

_

   if _Sound0 then goto __Skip_Joy0

   if joy0fire then _Sound0 = 1 : _Chan0_Duration = 15 : goto __Skip_Joy0

   if joy0up then _Sound0 = 2 : _Chan0_Duration = 30 : _V0 = 12 : goto __Skip_Joy0

   if joy0down then _Sound0 = 3 : _Chan0_Duration = 32 : _F0 = 31 : goto __Skip_Joy0

   if joy0left then _Sound0 = 4 : _Chan0_Duration = 32 : _V0 = 12 : _F0 = 31 : goto __Skip_Joy0

   if joy0right then _Sound0 = 5 : _Chan0_Duration = 32 : _C0 = 4 : _V0 = 12 : _F0 = 31

__Skip_Joy0

_

Thanks.

Link to comment
Share on other sites

They both have the same worst-case time, when the joystick is pressed right.

 

The bottom one will have better average and best case times, and use a wee bit more ROM.

 

It's also worth pointing out that they aren't quite equivalent. With the top example, if you press on a diagonal, it will trigger 2 if...then clauses. The bottom one only responds to cardinal directions.

  • Like 1
Link to comment
Share on other sites

They both have the same worst-case time, when the joystick is pressed right.

 

The bottom one will have better average and best case times, and use a wee bit more ROM.

 

It's also worth pointing out that they aren't quite equivalent. With the top example, if you press on a diagonal, it will trigger 2 if...then clauses. The bottom one only responds to cardinal directions.

Thanks. I probably screwed things up by making a last minute change just for this thread. Here is what the original two chunks of code looked like:

_

   if joy0fire && !_Sound0 then _Sound0 = 1 : _Chan0_Duration = 15

   if joy0up && !_Sound0 then _Sound0 = 2 : _Chan0_Duration = 30 : _V0 = 12

   if joy0down && !_Sound0 then _Sound0 = 3 : _Chan0_Duration = 32 : _F0 = 31

   if joy0left && !_Sound0 then _Sound0 = 4 : _Chan0_Duration = 32 : _V0 = 12 : _F0 = 31

   if joy0right && !_Sound0 then _Sound0 = 5 : _Chan0_Duration = 32 : _C0 = 4 : _V0 = 12 : _F0 = 31
_

 

   if joy0fire && !_Sound0 then _Sound0 = 1 : _Chan0_Duration = 15 : goto __Skip_Joy0

   if joy0up && !_Sound0 then _Sound0 = 2 : _Chan0_Duration = 30 : _V0 = 12 : goto __Skip_Joy0

   if joy0down && !_Sound0 then _Sound0 = 3 : _Chan0_Duration = 32 : _F0 = 31 : goto __Skip_Joy0

   if joy0left && !_Sound0 then _Sound0 = 4 : _Chan0_Duration = 32 : _V0 = 12 : _F0 = 31 : goto __Skip_Joy0

   if joy0right && !_Sound0 then _Sound0 = 5 : _Chan0_Duration = 32 : _C0 = 4 : _V0 = 12 : _F0 = 31

__Skip_Joy0
_

I should have just changed the second one instead of both of them:

_

   if _Sound0 then goto __Skip_Joy0

   if joy0fire then _Sound0 = 1 : _Chan0_Duration = 15 : goto __Skip_Joy0

   if joy0up then _Sound0 = 2 : _Chan0_Duration = 30 : _V0 = 12 : goto __Skip_Joy0

   if joy0down then _Sound0 = 3 : _Chan0_Duration = 32 : _F0 = 31 : goto __Skip_Joy0

   if joy0left then _Sound0 = 4 : _Chan0_Duration = 32 : _V0 = 12 : _F0 = 31 : goto __Skip_Joy0

   if joy0right then _Sound0 = 5 : _Chan0_Duration = 32 : _C0 = 4 : _V0 = 12 : _F0 = 31

__Skip_Joy0
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...