a note on std::complex performance

Gerhard Wesp gwesp@cosy.sbg.ac.at
Fri Sep 21 03:34:00 GMT 2001


hi!

i noted that, under certain circumstances, std::complex (with gcc-3.0.0)
is by a factor of 2-3 slower than with stlport.  my application is
simply the mandelbrot iteration, whose inner loop is

while( abs_squared( z ) <= max ) z = z * z + c ;

i looked at the implementation in libstdc++ and found that std::complex
is explicitly specialized for the floating point types and uses the
builtin complex type of gcc.  stlport does no such thing, and uses
simple inline functions for the operations.

my guess is that with stlport, the compiler can do much better
optimizations (reuse of common subexpressions) because it sees the
definition of the operations.  when using the builtin complex type, it
probably just generates library calls.

comments?

please cc replies to my email-address, i'm not on the list!

regards,
-gerhard



More information about the Libstdc++ mailing list