On Thursday 14 January 2010 07:14:28 boost-users-request@lists.boost.org wrote:
So I tried to improve performance on my first guess, namely
pow(x, 1/3) using boost::math::cbrt(). To my astonishment, this is much slower than the original code. I wrote a small test program to check this claim; compiling with g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1 (-O3) on a Intel Core i7 CPU I get the following timings (averaging the time over 10 trials): average time to compute 5000000 roots with pow(): 0.603 s. average time to compute 5000000 roots with boost::cbrt(): 1.087 s. average time to compute 5000000 roots with improved boost::cbrt(): 1.015 s. average time to compute 5000000 roots with exp(1/3*log()): 0.541 s.
I'll investigate that - I admit I haven't profiled that function up till now - and I suspect you're on the right lines by suspecting that the current implementation may be slow in finding the initial starting guess.
I suspect that some of the std:: functions may be faster if they're implemented as intrinsics, BTW have you tried ::cbrt in math.h ?
Cheers, John.
Hi! Thanks a lot for the suggestion: I didn't know that std::cbrt() exists! I alway relied on cplusplus.com as reference; I will have to change that! Of course this is again a lot faster: average time to compute 5000000 roots with pow(): 0.613 s. average time to compute 5000000 roots with cbrt(): 0.464 s. Thanks again - I am happy now... ;-) Tim