Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

dachande

Overhead of (int)float

This topic is 5985 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I just had a thought.. I am performing some calculations that in all honesty shouldn''t take a great deal of time to compute. Instead it takes 1.5 minutes to finish. When trying to decide what might be causing the problem, I see that I quite often cast a float to an integer using the syntax (int)float. Can anyone tell me what kind of overhead is involved in performing such as task iteration after iteration? Thanks, Dachande

Share this post


Link to post
Share on other sites
Advertisement
I promise you there is no way in heaven, hell or everything inbetween that that is slowing your program slow. There is overhead though since it creates an extra variable to do the cast, but fetching a new variable off the stack is very cheap. That''s not your problem though.

Share this post


Link to post
Share on other sites
Try using CodeAnalyst (from the AMD developer site) to profile your code - it should be able to tell you which bit is taking the most time to execute.

If you find that your app spends a lot of time inside the function ftol() then the float-->int conversion is taking up quite a bit of time. IIRC, under MSVC you can add the compiler switch /QIfist and it will generate a faster (but very slightly less accurate) conversion for you. If you''re using a lot of trig functions you might also want to take a look at the command "#pragma intrinsic" - MSDN has all the info there.

If you can post your code, do so and we''ll have a better chance of seeing what''s taking all the time.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
but then again, are you sure do you need to convert back and forth so often?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!