C++ computational efficiency
-
Hi I am currently building a time-critical app that requires a lot of computation functions, like sin(), log(), and sqrt(). I have two questions regarding this: 1. Is there an alternative way that is faster than using those functions? I am working on unsigned ints (32-bit) data, and building a lookup table would not be feasible, since there is no known boundary on the data. 2. Will C++ STL algorithm like for_each(), accumulate(), etc. make my app run faster than using traditional for loop? I am using VC++ 6.0 BTW, without STLPort. Thanks!
-
Hi I am currently building a time-critical app that requires a lot of computation functions, like sin(), log(), and sqrt(). I have two questions regarding this: 1. Is there an alternative way that is faster than using those functions? I am working on unsigned ints (32-bit) data, and building a lookup table would not be feasible, since there is no known boundary on the data. 2. Will C++ STL algorithm like for_each(), accumulate(), etc. make my app run faster than using traditional for loop? I am using VC++ 6.0 BTW, without STLPort. Thanks!
(1)The FPU can perform the basic sin/cos/ln functions in 'hardware' and therefore presumably quite quickly, more quickly than an integer based hand coded approach. So I suggest you convert your incoming fixed point data to floating, process it, then convert it back, examine the generated machine code and measure the performance. Only then explore the options. If you use the C library functions '
double sin( double )
' etc then the compiler should generate inline FPU code. (2)I don't think you'll see a significant performance difference for or against with the STL algorithms, but their use should make the code cleaner. Paul