Posted By: Zheka
Moving to floats from doubles? - 06/08/22 11:45
I would like to suggest to move Zorro's default 'var' from type double to type float.
Most trading system calculations involve looping over N prior values to do some sort of summing/dividing/multiplying.
With floats, 2X as many values will be prefetched to the CPU L1 cache, there will be fewer cache misses, and with c++ compilers auto-vectorization performance with floats on loops can be nearly 2X than with doubles.
Division, sqrt, pow, exp, log, trigonometric functions can be 2x faster with floats; TA_Lib also has a version that consumes float arrays.
I did some measurements several years ago - and the speed up was quite significant.
I understand type conversion for intermediate calculations can be costly, but this will occasional and a less common case than looping over N prices/values.
Float max value is big enough for overflow to occur very rarely, if ever.
What do you think?
Most trading system calculations involve looping over N prior values to do some sort of summing/dividing/multiplying.
With floats, 2X as many values will be prefetched to the CPU L1 cache, there will be fewer cache misses, and with c++ compilers auto-vectorization performance with floats on loops can be nearly 2X than with doubles.
Division, sqrt, pow, exp, log, trigonometric functions can be 2x faster with floats; TA_Lib also has a version that consumes float arrays.
I did some measurements several years ago - and the speed up was quite significant.
I understand type conversion for intermediate calculations can be costly, but this will occasional and a less common case than looping over N prices/values.
Float max value is big enough for overflow to occur very rarely, if ever.
What do you think?