0

I have this algorithm set (In my mind) which requires me to cast float to int many times in a loop(about 300 times for each 16 milli seconds) . My question is this:

How costly is process of casting from float to int in java/android and will it cause the game to slow down ?

Is it cheap enough to be implemented by my game? if not, what are the other options to convert decimal to integer?

Edit: Question solved!

12
  • I'd say that you are safe with casting it to an int 300 times in 16 milliseconds. The question about how costly the process is is interesting, but I think you have better things to worry about. Commented Dec 21, 2012 at 2:46
  • 300 times / 16 milli-seconds isn't a lot. Commented Dec 21, 2012 at 2:46
  • 2
    Have you done any performance profiling? Commented Dec 21, 2012 at 2:47
  • it isn't a lot on its own but I have some other algorithms to be implemented in the 16 milli seconds including the time taken by android system to draw the frame... Commented Dec 21, 2012 at 2:48
  • @SimonAndréForsberg "I'd say that youre safe"? maybe you should cite your sources? :) Commented Dec 21, 2012 at 2:48

1 Answer 1

1

A cast from float to int doesn't cost any more than any other assignment statement. It is handled by the hardware. An assignment (depending on the architecture) typically costs a single cycle or one trip through the pipeline (very, very fast). I wouldn't worry about the impact of this conversion on your performance.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.