+Random Terrain Posted March 13, 2015 Share Posted March 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
RevEng Posted March 13, 2015 Share Posted March 13, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted March 13, 2015 Author Share Posted March 13, 2015 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 Quote Link to comment Share on other sites More sharing options...
ZackAttack Posted March 14, 2015 Share Posted March 14, 2015 I'd say the skipping gotos has a speed advantage because the!_sound0 condition can be done once at the beginning like you have in the original post. So you'll end up with less comparisons in the worst case scenario. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.