In what situations is it better to use a float over a double in Java?
double, java, performance
Solution
Since your question is mostly about performance, this article presents you with some specific calculations (keep in mind though that this article is specific to neural networks, and your calculations may be completely different to what they're doing in the article): http://web.archive.org/web/20150310213841/http://www.heatonresearch.com/content/choosing-between-java%E2%80%99s-float-and-double
Some of the relevant material from the link is reproduced here:
Both double and float can support relatively large numbers. The upper and lower range are really not a consideration for neural networks. Float can handle numbers between 1.40129846432481707e-45 to 3.40282346638528860e+38...Basically, float can handle about 7 decimal places. A double can handle about 16 decimal places.
Matrix multiplication is one of the most common mathematical operations for neural network programming. By no means is it the only operation, but it will provide a good benchmark. The following program will be used to benchmark a double.
Skipping all the code, the table on the website shows that for a 100x100 matrix multiplication, they have a gain in performance of around 10% if they use doubles. For a 500x100 matrix multiplication, the performance loss because of using doubles is around 7%. And for a 1000x1000 matrix multiplication, that loss is around 17%.
For the small 100x100 matrix switching to float may actually decrease performance. As the size of the matrix increases, the percent gain increases. With a very large matrix the performance gain increases to 17%. 17% is worth considering.
Problem
More specifically, how extreme is the performance gain when using a float instead of a double in Java?