Boost logo

Boost Users :

Subject: Re: [Boost-users] [math][special_functions] Why is cbrt(x) slower thanpow(x, 1/3)?
From: John Maddock (john_at_[hidden])
Date: 2010-01-13 12:18:47


> 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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net