"Komag" wrote:
So the question really: Is a set of four single line IF THEN statements run more efficiently under-the-hood in BrightScript than a single block IF THEN using multiple ELSEIFs?
I prefer Option C ( which a few of the Gurus would have to approve / improve on
😞Direction could be a vector... Up == (0, -1), Down == (0, 1), Left == (-1, 0), Right == (1, 0)
Then after checking for isStepping, no more IF's:
curX = curX + 4 * Direction.X ' or ... direction[0]?
curY = curY + 4 * Direction.Y ' or ... direction[1]?
I'll add that I've been taught (*cough* EnTerr *cough*) that using dictionary look-ups is slow and something you don't want to do in a loop. I've not tested this or know for fact how slow it would be to use a Dictionary ( roAA ) of only 2 values { x : ?, y : ? } But either way, converting that to a roArray wouldn't be too difficult / confusing to follow ( with a comment line or two ).
Yet, the dictionary look-up "performance hit" might have more to do with using the roAA "mAA" instead... dunno.
I'll also add that this "solution" might actually be slower! due to having a multiply instead of an add... but I like it better for unknown reasons.
😉 Finally I'll *ADD* one last tid-bit... as stated, if you don't nest your IF's your code will be doing extra work on average, BUT the nested IF's won't be a uniform amount of time thru that part of your code. *THAT SAID* does any of this really matter? Isn't this a very small optimization in the whole scheme of things?
As difficult as it might be, not that I do this first and foremost, but I'd say go with readable/maintainable code and optimize it later when/if you *NEED* to.
"Premature optimization is the root of all evil (or at least most of it) in programming." -- Donald Knuth
http://en.wikiquote.org/wiki/Donald_Knuthpeace, Happy Thanksgiving & 42
ps - I tried... I really tried *not* to make mention of this being my 42nd post. So, I won't.
😛