<div class="gmail_quote">On Sun, Jul 11, 2010 at 10:35 PM, Max S. Kaznady <span dir="ltr">&lt;<a href="mailto:max.kaznady@gmail.com" target="_blank">max.kaznady@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

I wrote some benchmarks for Boost and GSL where I initialize a vector<br>
of random numbers and then raise it to some random exponent, and I<br>
redo the operations a certain number of times and report the average<br>
time.<br>
<br>
std::transform and std::for_each take the same time, GSL&#39;s filling in<br>
manually and Boosts&#39;s filling in manually also take the same time BUT,<br>
manual fil is a bit faster than using std::transform and<br>
std::for_each. Any ideas why?<br>
<br>
Runtimes:<br>
Boost vector initialization:<br>
0.000000000000000<br>
GSL vector initialization:<br>
0.000000000000000<br>
Boost transform avg time:<br>
0.002141000000000<br>
Boost for_each avg time:<br>
0.002094000000000<br>
Boost manual fill avg time:<br>
0.001811000000000<br>
GSL avg time:<br>
0.001820000000000<br>
<br>
</blockquote></div><br>Hi Max<br><br>First thing I should say is that I am NOT in any sense an expert on the finer<br>aspects of performance, so you may want to take anything I say with a large<br>dose of salt!<br><br>Second, I am reminded of the much quoted rules of optimization<br>
<br>* Don&#39;t<br>* Don&#39;t yet (for experts)<br>* If you must, profile first<br><br>Obviously you are profiling, but is it conclusive? What is the statistical uncertainty<br>in your results, especially compared to the observed differences?<br>
<br>All that said, I am unsurprised that hand rolled loops are a little faster. Using algorithms<br>also uses a Boost.Bind invocation on each iteration, with all the overhead and lack<br>of localisation that implies. You might want to try custom functors (inlined), to see how<br>
the performance numbers compare.<br><br>However, stepping back, does your application really require the last word in performance?<br>In most of your code, would clarity and expressiveness be more valuable that a small<br>
performance boost? Would your numbers be repeated in a more realistic application, and<br>would these performance differences be significant against a broader background?<br><br>Regards<br><br>- Rob.<br><br>

