Speed of floating point types in C

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):

long double0.0352610.003683

For Intel Intel(R) Core(TM) i7-8700T CPU @ 2.40GHz and SODIMM DDR4 Synchronous 2400 MHz:

long double0.0210980.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.

in All, C programming,
Copyright 2021-2022 Baillehache Pascal