User Tag List

Results 1 to 10 of 10

Thread: Fastest way to compare values?

  1. #1
    Clicker

    Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleUnicode Add-onInstall Creator Pro
    StingRay's Avatar
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    1,057
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Fastest way to compare values?

    Hi! Very often i have to compare mathematical expressions in loops. to speed them up, i first store the expression result in a value.
    Then i compare this value with another - I'm looking for the most effective way to do that - now my question:

    is it faster to compare

    a) 2 counters
    b) 2 Alterable Values
    c) 2 Global Values

    ?

    Thanks for your suggestions

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,307
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I think that they would all be equally fast, except for maybe a counter, which would be slower as long as it isn't a hidden counter, as it would also need to display an object in addition to holding the values. If you made it a hidden counter, then it would probably be faster. Also, another thing to note is that directly comparing the mathematical expressions might actually be even faster. Over all, though, such minor things aren't going to affect performance significantly at all, so you should probably do it in the way that is most readable to you.

  3. #3
    Clicker

    Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleUnicode Add-onInstall Creator Pro
    StingRay's Avatar
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    1,057
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Just an example, Happygreenfrog:

    I've about 200 shops and calculate the distance from the user in a loop by:

    ((ACos(Sin(value( "lat1" ))*Sin(Lat( "data" ))+Cos(value( "lat1" ))*Cos(Lat( "data" ))*Cos(Lon( "data" )-value( "long1" )))*6371.0)/180.0*3.141592654)+((ACos(Sin(value( "lat1" ))*Sin(Lat( "data" ))+Cos(value( "lat1" ))*Cos(Lat( "data" ))*Cos(Lon( "data" )-value( "long1" )))*6371.0)/180.0*3.141592654)/5.0+1.0)

    if i replace the value Lat("data") with the REAL value [ValAtXY( "Array", 6, LoopIndex("write")+2))] it would effect performance, i think.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,307
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    With a long calculation like that, I can see what you mean. Okay, then, I think an alterable value would be the best way to go, then, unless you need the data to be carried from frame to frame, in which case, you should use a global value.

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,367
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    I did a simple test where I run a loop 500.000 times and add 1 to either a global value, a counter or an alterable value.

    Results when adding:
    Global Value: 11fps
    Alterable Value: 9fps
    Hidden Counter: 7fps
    Number Counter: 3fps

    However, when comparing values instead of adding I get these results:

    Results when comparing:
    Global Value: 20fps
    Alterable Value: 40fps
    Counter: 40fps

    So it seems Alterable values and counters are both equally good when comparing values and is the preferable choice.

  6. #6
    Clicker

    Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleUnicode Add-onInstall Creator Pro
    StingRay's Avatar
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    1,057
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    great test, Popcorn! thanks alot! i think this will be a great ressource

    btw: how do you get a FPS when a loop is running?

  7. #7
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export ModuleUnicode Add-on
    Looki's Avatar
    Join Date
    Aug 2006
    Location
    Karlsruhe, Germany
    Posts
    3,741
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    For one thing you could precalculate all values that are used twice, StringRay (the sin/cos stuff). Also, constant expressions such as 1.0/180.0*3.141592654 = 0.01745329252

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,367
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StingRay View Post
    how do you get a FPS when a loop is running?
    You don't. Simply check the fps after the loop is finished.
    Always: Run loop 500.000 times
    Always: Set Counter to Framerate

  9. #9
    Clicker

    Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleUnicode Add-onInstall Creator Pro
    StingRay's Avatar
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    1,057
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the find, Looki!

  10. #10
    Clicker Multimedia Fusion 2SWF Export Module

    Join Date
    Sep 2006
    Posts
    1,544
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Using mathematics in the expression editor can indeed be more efficient than redundant object scoping and comparisons
    Just make sure to write yourself a comment that says exactly what that line of code is doing and what those formulas or for, otherwise this is an incomprehensible mess:


Similar Threads

  1. Trying to use OR in a condition to compare more than two values at once...
    By alxmrg in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 25th January 2012, 05:47 PM
  2. 'Compare to one of the alterable values' VS 'Compare two general values'
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 1st January 2012, 06:26 PM
  3. For each and compare two general values
    By Popcorn in forum Multimedia Fusion 2 - Technical Support
    Replies: 13
    Last Post: 29th April 2010, 05:03 AM
  4. Compare Multiple Values?
    By Dynamite in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 2nd June 2009, 12:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •