Posted by

chaose on November 14, 2008 at 6:45 AM PST

Hello Everyone,

today we stumbled upon a huge performance leak while optimizing a raycasting algorithm. Much to our surprise, the Math.floor() method took almost half of the calculation time: 3 floor operations took the same amount of time as one trilinear interpolation. Since we could not belive that the floor-method could produce such a enourmous overhead, we wrote a small test program that reproduces the behavuior (tested in a 64bit and a 32bit Java environment).

The test program adds 5000000 floored/casted random double numbers. Here the reproducable results:

Casting ... Result = 10001538 (31 ms)

Rounding ... Result = 10001538 (344 ms)

The numbers differ that much that we are still unsure if we overlooked something stupid. Anyhow, the original raycasting algorithm runs twice as fast with casting ;)

Best Greetings,

ChaosE