Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Sep 02, 2013 at 12:06 AM by DeadKenny for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DeadKenny · Sep 01, 2013 at 11:27 PM · c#performancefloatintcpu

Floats and int performance difference?

Is there a difference when using floats and or ints.

Like say for calculating the distance between objects or the rotation speed, is it better to use ints or floats. Will it make a difference to CPU?

I am asking because I have recently dug up an old code(tutorial) that uses ints for things like rotationSpeed and maxSpeed, which I usually use floats for.

I am noticing smoothness differences in rotations of objects or so I think. Not sure actually.

So yeah is there a performance difference between ints and floats when using it for such things as speed, rotationSpeed, etc?

Thanks.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShadoX · Sep 01, 2013 at 11:44 PM 1
Share

I doubt that it would make much of a difference for the PC unless you're looking at the memory usage where Ints usually seem to use 2 bytes while floats use 8. The reason why you see a difference in rotation is that int only contains whole numbers while floats also contain fractions which means a more accurate result. Have a look at http://en.wikipedia.org/wiki/Integer_(computer_science) and http://en.wikipedia.org/wiki/Double-precision_floating-point_format

avatar image DeadKenny · Sep 02, 2013 at 12:06 AM 0
Share

Cool thanks.

avatar image Eric5h5 · Sep 02, 2013 at 12:13 AM 2
Share

Ints and floats both use 4 bytes. Shorts use 2 bytes, and doubles use 8, but you wouldn't commonly use those in Unity.

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Jamora · Sep 02, 2013 at 12:00 AM

Have a look at what the people at Stack Overflow have to say: floating point vs integer calculations on modern hardware. 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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeadKenny · Sep 02, 2013 at 12:06 AM 0
Share

Ah cool thanks.

avatar image aldonaletto · Sep 02, 2013 at 01:49 AM 0
Share

Totally agree: the difference, if any, is negligible. Anyway, scripts do too little calculation to deserve such optimization. Recalculating matrices every frame (a Unity's job) usually is much heavier, and the real donkey work is done by the GPU: many thousands of float operations per frame. This kind of optimization was very important in the past (when Quake was launched), because GPUs didn't calculate anything.

avatar image
1

Answer by AFDozerman · Sep 02, 2013 at 12:15 AM

Generally speaking, it shouldn't be any noticable difference, although it really depends on your processor. An AMD FX series is going to have a faster single threaded floating point performance metric with significantly slower floating point multithreaded metric. Intel's should be more even.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is There A Way To Cast On 1 Returning Value 2 Times? 5 Answers

Cannot implicitly convert type `float' to `int'. An explicit conversion exists (are you missing a cast?) 1 Answer

Can I create a list with an int/float and a string? C# 2 Answers

C# Int to Float conversion performance 3 Answers

How to i set the int to hitpoints / 10 + the current int. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges