::pow(T, n) vs std::pow(T, n) for non-constant n
Paolo Carlini
pcarlini@suse.de
Sun Mar 14 12:26:00 GMT 2004
... however, for the very same loop that I used at the beginning:
for (int i = 0; i < 100000000; ++i)
{
double a = M_PI * i;
int n = i % 10;
std::pow(a, n);
//::pow(a, n);
}
With -O2 -ffast-math <- IMPORTANT
::pow
-----
0.090u 0.000s 0:00.09 100.0% 0+0k 0+0io 149pf+0w
std::pow
--------
1.540u 0.000s 0:01.54 100.0% 0+0k 0+0io 149pf+0w
Therefore, in the situation displayed above, gcc + builtin pow,
when requested to do so (-ffast-math) is able to establish the
constness of the argument and use the fast optimized code!!!
For sure, in other, more complex, situations this will not happen,
but when, exactly?
The more I try out the behavior of gcc + builtin pow, the more I
become convinced that, for -ffast-math, is so faster than the current
v3 binary algorithm, otherwise, more accurate.
Paolo.
More information about the Libstdc++
mailing list