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-17 12:36:10


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

FYI SVN Trunk now has an updated algorithm that is very competitive - within
1-2% of ::cbrt (gcc-4.4.1 on Ubuntu Linux):

Testing cbrt 1.025e-07
Testing cbrt-c99 1.001e-07
Testing cbrt-pow 1.611e-07

Unfortunately msvc performance compares less well (even though it's much
better than before, and does at least outperform the cephes lib):

Testing cbrt 1.970e-007
Testing cbrt-cephes 2.676e-007
Testing cbrt-pow 1.072e-007

This reflects the poor performance of std::frexp on that compiler...
annoying that :-(

Regards, 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