Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Performance optimizations: float or int?

    Advanced
    performance
    4
    7
    678
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • spikey
      spikey F last edited by spikey

      I am trying to increase the speed of several functions. In other languages one thing to do is using int instead of float as the variable type wherever possible.

      So, I suddenly found out, that the functions clamp(), min() and max() always return their result as a float, even if the input parameters are all of the type int.

      Did anyone of you make the experience that it makes a difference in FUZE if int or float is used for heavy calculations?

      1 Reply Last reply Reply Quote 1
      • Dave
        Dave Fuze Team last edited by

        Thanks @spikey we'll look into this.

        1 Reply Last reply Reply Quote 1
        • spikey
          spikey F last edited by spikey

          I still cannot say, if it makes a difference at the end (maybe if my project is finished) but a vector always converts intinto float, too. So, currently no need to change anything I guess, until we come to the conclusion, that this would help with speed. Sooner or later I can tell.

          a = {1,2,3,4}
          print(a)
          update()
          sleep(10)
          

          output:

          {1.000000, 2.000000, 3.000000, 4.000000}
          
          1 Reply Last reply Reply Quote 0
          • AndyG1985
            AndyG1985 last edited by

            Funny you mention this, I only started using “float” very recently when I noticed others were doing it. If I wanted to use a variable within a function, I used to just write e.g lives = 0 before starting the function. I still don’t really know how this is better - just that my code now looks more like the smart guys’ code! I do know that ”var” doesn’t work in the same way.

            1 Reply Last reply Reply Quote 1
            • spikey
              spikey F last edited by spikey

              @andyg1985

              • var just says: hey, I need to store something later, but I don't know yet, what it would be. (For me it feels like a soft-declaration).

              • int lives is the normal declaration, careful when you read from them, before writing something into it (can be void, I think for arrays).

              • lives = 0 is the definition. But in FUZE its a combo, because it automatically does a declaration (here as an int if you didn't before).

              Just saw, you are a veteran coder, man: you did Tycoon Dizzy? What am I writing here... 🤭

              1 Reply Last reply Reply Quote 1
              • AndyG1985
                AndyG1985 last edited by

                Hahaha! Well thanks. Maybe don’t look at the actual coding and we’ll go with that :). I will keep using float as it seems to be working for me so far, and seems less like cheating, to say lives=0 when I don’t know what lives should equal just yet.

                1 Reply Last reply Reply Quote 1
                • joyrider3774
                  joyrider3774 last edited by joyrider3774

                  i think switch has HW FPU so doing integer maths or floating points does not show that big a off a difference as it would on systems using softfloat where fixed point math would help in that case (represent floats in integers and do calculation using the integer representations so that your not doing floating point maths but integer maths which is faster) and even if it does not it's got plenty of speed. It's not like your developping for some 200mhz device without floating point unit about 20 years ago i had such problems with gp2x but fixed point maths fixed that. But fuze will probably slow down more from doing lots of small (self written) function calls (depending on use case or when trying todo fixed point math) than doing floating point maths directly

                  edit: according to wikipedia switch uses tegra chip and ARM Cortex-A57 which has hw FPU

                  also you can easily time stuff using time() function and do little benchmarks, if you really want to investigate for example time 10000 or even 100000 time doing integer division and then do simiar using floating point division and compare times. Doing a single division will not give accurate results to compare as it completes way too fast to measure

                  T = Time()
                  Do Some things you want to benchmark
                  Printat(0,0, Time() - t)
                  
                  1 Reply Last reply Reply Quote 2
                  • First post
                    Last post