I was curious about the influence on speed of the floating point types, so I've made a quick test. I leave the results here for reference.
In C there are three possible types to represent real numbers: float, double, long double in increasing order of precision and increasing size in memory (for a 64bit machine). To test there influence on speed I've made the following simple test: for each type, create a data structure representing a 3D vector using that type, calculate a bunch of dot product on instances of these structures, and measure and compare the execution time. The code is as follow:
(Edited on 2022/10/15 to add results on different architecture)
The results are as follow. For "11th Gen Intel(R) Core(TM) i3-1125G4 @ 2.00GHz" (from cat /proc/cpuinfo) and Row of chips LPDDR4 Synchronous 4267 MHz (from lshw -C memory):
Type | -O0 | -O3 |
---|---|---|
float | 0.010576 | 0.001301 |
double | 0.010747 | 0.002577 |
long double | 0.035261 | 0.003683 |
For Intel Intel(R) Core(TM) i7-8700T CPU @ 2.40GHz and SODIMM DDR4 Synchronous 2400 MHz:
Type | -O0 | -O3 |
---|---|---|
float | 0.008563 | 0.001006 |
double | 0.008829 | 0.002198 |
long double | 0.021098 | 0.002660 |
Without the optimisation turned on, there is no significative difference between float and double. With optimisation turned on float is around twice faster than double. In both case long double is significantly slower than the two other types.