|
Boost Users : |
Subject: Re: [Boost-users] apply std::pow to vector or matrix
From: Max S. Kaznady (max.kaznady_at_[hidden])
Date: 2010-07-13 11:03:18
Actually, in the code I have to first fill a vector and then apply an
operation, so if I'm just applying the operation then Boost is faster
with iterators (manually, I can fill and apply the operation in one
line of code; for iterators it's 2 lines). There is also quite a lot
of uncertainty (I included unbiased std dev estimates):
Boost transform avg time:
0.001945000000000 +/- 0.003958350900841
Boost for_each avg time:
0.001751000000000 +/- 0.003800716188346
Boost manual fill avg time:
0.001591000000000 +/- 0.003657876023829
GSL avg time:
0.001625000000000 +/- 0.003689273109110
I agree - using iterators it the way to go. The code is more readable,
and you do actually get a performance boost, since most of the time
you're not filling the vector and applying an operation - you are just
applying an operation to a vector which has already been filled.
Cheers,
Max
On Mon, Jul 12, 2010 at 4:02 AM, Robert Jones <robertgbjones_at_[hidden]> wrote:
> On Sun, Jul 11, 2010 at 10:35 PM, Max S. Kaznady <max.kaznady_at_[hidden]>
> wrote:
>>
>> I wrote some benchmarks for Boost and GSL where I initialize a vector
>> of random numbers and then raise it to some random exponent, and I
>> redo the operations a certain number of times and report the average
>> time.
>>
>> std::transform and std::for_each take the same time, GSL's filling in
>> manually and Boosts's filling in manually also take the same time BUT,
>> manual fil is a bit faster than using std::transform and
>> std::for_each. Any ideas why?
>>
>> Runtimes:
>> Boost vector initialization:
>> 0.000000000000000
>> GSL vector initialization:
>> 0.000000000000000
>> Boost transform avg time:
>> 0.002141000000000
>> Boost for_each avg time:
>> 0.002094000000000
>> Boost manual fill avg time:
>> 0.001811000000000
>> GSL avg time:
>> 0.001820000000000
>>
>
> Hi Max
>
> First thing I should say is that I am NOT in any sense an expert on the
> finer
> aspects of performance, so you may want to take anything I say with a large
> dose of salt!
>
> Second, I am reminded of the much quoted rules of optimization
>
> * Don't
> * Don't yet (for experts)
> * If you must, profile first
>
> Obviously you are profiling, but is it conclusive? What is the statistical
> uncertainty
> in your results, especially compared to the observed differences?
>
> All that said, I am unsurprised that hand rolled loops are a little faster.
> Using algorithms
> also uses a Boost.Bind invocation on each iteration, with all the overhead
> and lack
> of localisation that implies. You might want to try custom functors
> (inlined), to see how
> the performance numbers compare.
>
> However, stepping back, does your application really require the last word
> in performance?
> In most of your code, would clarity and expressiveness be more valuable that
> a small
> performance boost? Would your numbers be repeated in a more realistic
> application, and
> would these performance differences be significant against a broader
> background?
>
> Regards
>
> - Rob.
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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