Boost logo

Boost :

Subject: [boost] tuple benchmarks show marked differences from std::tuple(was Re: Interesting article on stack-based TMP
From: Larry Evans (cppljevans_at_[hidden])
Date: 2012-10-24 11:47:10


(renaming from Re: Interesting article on stack-based TMP)
On 10/23/12 11:05, Eric Niebler wrote:
> (dropping the boost-users list...)
[snip]
>
> I don't want the results of my early experimentation with variadic
> templates to be used to draw conclusions about the feature. What Larry
> says is true, but in part it was due to my own naivete. Variadic
> templates are very good for *some* things, like perfect forwarding.
> Other things can be done in very tricky ways of which I was not aware at
> the time, like getting O(1) access to the back of a template parameter
> pack.
Could you please explain this O(1) trick briefly?
> And yeah, sometimes preprocessing can still improve compile-times.
> Without random access into a parameter pack, a data structure like
> std::tuple is a massive, bloated TMP hog.
[snip]
The attached is the output .txt file produced by running:

http://svn.boost.org/svn/boost/sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_run.py

while in the working directory produced by `svn checkout` on the above
svn directory. It shows that with std::tuple, the compile times are 4
times as long as with the "horizontal" tuple implementation which uses
no preprocessing. It also shows the "horizontal" is about the same as
the "vertical" which does use preprocessing. The "horizontal" trick
(as Douglas Gregor has explained elsewhere) is to use multiple
inheritance where the tuple elements are "paired" with the key to
retrieve them.

I thought it also interesting that clang seems to do better than gcc,
as reported here:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54710#c10

HTH.

-regards,
Larry




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk