I’m developing an Android game. At the moment I’m writing code that should calculate the best route between two objects, using the A* algorithm. Inside the algorithm i’m using doubles to calculate everything.
When running time consuming algorithms on my computer the time difference between calculating with Integers and Doubles is almost zero (maybe a few nanoseconds).
Question one:
Can this behavior also seen on Android phones? I know my computer has multiple ALU’s one for integers on for floating points etc. But how about phones? Android phones can be very different when it comes down to hardware. I only have two test phones, but today there are hundreds of phones available on the market, which means that running tests on two of my phones would not give me reliable data, at least that’s what I think.
Question two:
For my game it doesn’t matter allot if I switch to Integers, the calculated route maybe less perfect but that doesn’t bother me. So is it worth switching to integers? Or would switching to integers break the algorithm? Does anyone have experience with this?
As a general rule of thumb, integer arithmetic is faster than floating point arithmetic because it is simpler to implement. (With floating point, the hardware has to deal with both the mantissa and exponent parts, and (AFAIK) it cant do this in parallel.)
However, the performance ratio is going to vary from one hardware implementation to the next, and it is hard to make predictions that are any better than guessing. (For a start, it depends on marketing strategies and performance vs battery life tradeoffs.)
But to be honest, I’d be focusing more on which of integer and floating point is going to work best with your game’s algorithms. If they require one and you use the other, then you are in for a lot of pain (unnecessary coding, testing, bug fixing, etc).
It could do. It could also make them a lot more complicated. It all depends on the nature of the algorithms. Certainly, you are in for a lot of recoding and retesting.
Personally, I’d only contemplate doing this if the game was simply too slow even after I’d tried profiling and tuning the performance hotspots. And I’d only do it if I was prepared to take the risk that the re-coding effort might achieve no benefit … or worse.