Boost logo

Boost Users :

Subject: Re: [Boost-users] apply std::pow to vector or matrix
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2010-07-12 04:02:53


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