Performance using int over float in editor
I'm asking this out of curiosity, it may seem minor ;)
Would using whole numbers in the attached example (or transform, etc) offer any performance gain across a project?
Answer by Graphics_Dev · Aug 23, 2016 at 05:15 PM
This is a duplicate question. You can read these posts about the topic (this is by no means exhaustive):
http://answers.unity3d.com/questions/528607/floats-and-int-performance-difference.html
In short, the general consensus seems to be "it depends". My personal opinion is that in games, this kind of optimization is useless. Your time would be better spent optimizing your memory allocations (reducing garbage) or moving unnecessary computation out of the Update function.
http://forum.unity3d.com/threads/int-vs-float.64290/
Doing basic math operations with int is around 30% faster than float. If you need to save RAM and your integer numbers are small enough, you can use short (System.Int16) or even byte instead of int, however int32 is a little faster than both. On a desktop CPU anyway; not sure about ARM. Oh yeah, and certain operations like various bitwise operators can only be done on integers.
Thanks for the fast reply.
Do you know if this is true for in-editor variables? (i.e. are editor variables always float or is the type dynamic).
I do not know...I would assume it is not always stored as a float, but I don't know for sure. By in-editor you mean variables for editor scripts?
If this answered your question please accept my answer.
I mean all the position values in transform, etc. or in attached photo above the offset and size. Generally whenever putting a value in the editor without being explicit about what type you are using.
I was wondering if it would be worth me adjusting them to whole values or if there was no performance implication.
Does this make sense?
Please don't leave comments as answers in the future.
I fixed it for you this time :-)
Your answer
Follow this Question
Related Questions
Entering playmode from editor is very slow 0 Answers
Low fps in scene editor and game view 1 Answer
Why does my Scene View use 100% processor 0 Answers
Scene view performance 0 Answers
5.4 GB of RAM used by editor. 1 Answer