1 Reply Latest reply on Dec 5, 2011 2:56 PM by philmodjunk

    Performance: Set Variable vs Calling Functions?

    CampbellSoup

      Title

      Performance: Set Variable vs Calling Functions?

      Post

      Hello World,

       

      Please forgive me if this has been posted before, I could not find the subject here after a cursory search. I'm new to developing in FMP and was wondering if there is a significant performance difference between calling a function once to set a variable for comparison vs calling said function for each comparison instead. For example:

      1. Set Variable $variable = Get(CurrentHost)

          If($variable...etc)

          ElseIf($variable...etc)

      As opposed to

      2. If( Get(CurrentHost)...etc)

          ElseIf( Get(CurrentHost...etc)

       

      What is the tradeoff and which is considered "best practice"? Thoughts?

      Thanks!

        • 1. Re: Performance: Set Variable vs Calling Functions?
          philmodjunk

          It depends on the functions and, in some cases, the number of records in your database. Simple functions like Get ( currentHost ) or Get ( CurrentDate ) may execute so quickly that you cannot tell the difference unless this is in a loop cycling through 1000's of records or some such.

          In which case, the variable might be the faster alternative.

          This is definitely true for aggregate functions such as Sum, Average, Std Dev. If they are used to produce an aggregate value from 1000's or hundreds of 1000's of related records, then computing the value once will clearly be faster.