
For a (cell) simulation code I have to calculate lots of cubic roots in every timestep. 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.