Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Small performance question — Gideros Forum

Small performance question

antixantix Member
edited June 2017 in General questions
Can anyone enlighten me to which of the following runs faster? I searched but couldn't find anything myself :(
  if animName1 ~= "" then
    if actor.animName2 ~= animName1 then
      -- do stuff
    end
  end
 
  if animName2 ~= "" and actor.animName2 ~= animName2 then
    -- do stuff
  end

Comments

  • tkhnomantkhnoman Member
    edited June 2017 Accepted Answer
    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" then
        if object ~= caller then
     
        end
    end
    And the second for some stacked condition, for example :
    if object.isChar 
    and not object.isFlying 
    and not object.isDead then
    end
    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.
  • SinisterSoftSinisterSoft Maintainer
    edited June 2017
    @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.

    Likes: antix

    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
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.