I think you should not bother about this stuff to much. It differs in a super little time, and it doesn't affect performance at all.
The main difference in my mind is that, how would you want to organize your code. I often also use the first because of some "easier reading" things. For example,
if object.name =="a"thenif object ~= caller thenendend
And the second for some stacked condition, for example :
if object.isChar
andnot object.isFlying
andnot object.isDead thenend
Just code the way you want. I also don't bother using "/" instead of "*" in calculation, even they said multiplication is faster than divide. But if using "/" somehow needed for easier reading, then i don't bother thinking about it too much.
@antix As they are functionally identical then export the code. See which makes the most bytecode (the size of the lua programs exported), the larger one should be slightly slower as it has more bytecode to run though - if you are doing this millions of times though then it could make a difference overall.
I suspect the 2nd method will be the faster of the two.
Also, I might be wrong, but in the first method, the second if will have some extra bits to do because of possible localisation (for each of the if then's), but the 2nd method won't need to do this.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Comments
It differs in a super little time, and it doesn't affect performance at all.
The main difference in my mind is that, how would you want to organize your code.
I often also use the first because of some "easier reading" things.
For example,
I also don't bother using "/" instead of "*" in calculation, even they said multiplication is faster than divide. But if using "/" somehow needed for easier reading, then i don't bother thinking about it too much.
I suspect the 2nd method will be the faster of the two.
Also, I might be wrong, but in the first method, the second if will have some extra bits to do because of possible localisation (for each of the if then's), but the 2nd method won't need to do this.
Likes: antix
https://deluxepixel.com