|
Boost Users : |
Subject: Re: [Boost-users] [math][special_functions] Why is cbrt(x) slower than pow(x, 1/3)?
From: Tim Odenthal (Tim.Odenthal_at_[hidden])
Date: 2010-01-14 06:45:15
On Thursday 14 January 2010 07:14:28 boost-users-request_at_[hidden]
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
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