I'm learning BBC BASIC while writing a game, and yesterday was all about speed-optimising the main loop. Thanks in no small part to some great insight from others in another thread, I thought I'd reached the point of diminishing returns.
But last night I finally addressed two lines of code that had been nagging me from the start:
Code: Select all
217IFU%>20ANDX%>=L%ANDX%<=M%A%=FNC(I%)
220IFU%>20ORABS(X%)>292U%=RND(2):S%?I%=U%:X%=RND(440)-220:C%?I%=RND(7)
Code: Select all
214IFU%<21THENGOTO220
217IFX%>=L%ANDX%<=M%A%=FNC(I%)
218U%=RND(2):S%?I%=U%:X%=RND(440)-220:C%?I%=RND(7)
220IFABS(X%)>292U%=RND(2):S%?I%=U%:X%=RND(440)-220:C%?I%=RND(7)
But it gave me a time reduction of 3.5%, which I don't want to give up just for the sake of good practice. At this late stage in optimisation, that's a huge gain.
I've also just now realised that I can optimise it a bit further by adding 219GOTO240, since at that point, line 220 is redundant. I just made that change now, and while I was hoping for better gains, it is a tiny improvement.
So TWO GOTOs, and ONE repetition of code.
Is this justified, or is there a better way?