Quick Links: Gideros Home | Download Gideros | Developer Guide
Small performance question
  • antixantix +1 -1
    Member
    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
    Check out my DevBlog, my GitHub, and my games Falling Animals | Breaky Wall | Exetor
  • tkhnomantkhnoman +1 -1
    Member 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.
  • antixantix +1 -1
    Member
    @tkhnoman thanks.
    Check out my DevBlog, my GitHub, and my games Falling Animals | Breaky Wall | Exetor
  • SinisterSoftSinisterSoft +1 -1 (+1 / -0 )
    Maintainer
    @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

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID

In this Discussion

Top Posters