Optimising Code – When Built In Methods Aren’t Fast Enough

Hi All,

I have recently being trying to get some further optimisations out of the world generation which has been a little bit of a bottle neck for a while. Running through the Unity profiler I found that my Perlin noise was one of the contributors to high CPU time.

After some investigation I found an article that mentioned a “fast floor” method. It got me thinking about the built in Unity Mathf.Floor and Mathf.FloorToInt methods and there performance. After a setting up some quick benchmarks using looping and stopwatches I benchmarked the Unity method against the one I built based of the mentioned article I found that the new method was twice to four times faster.

Implementing the method resulted in a substantial performance improvement. As can be seen in the above image the Floor methods are quicker and as they are used in a few places you can see the overall behaviour call is over 10% better. These performance results were done in engine and suffer a bit from that over head but as you can see in the below the frame rate in game.

We also have some very exciting news to announce soon, so keep an eye out for that too.



Leave a Reply

Your email address will not be published. Required fields are marked *