Boost logo

Boost :

Subject: Re: [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-26 09:27:09


On 10/25/12 11:58, Larry Evans wrote:
> On 10/24/12 14:09, Eric Niebler wrote:
> [snip]
>> I presented at BoostCon my own benchmarks of tuple with and without
>> preprocessing.
[snip]
>>
>> The source code is here:
>>
>> https://github.com/ericniebler/home/tree/master/src/tuple
>>
>
> I downloaded that and AFAICT:
>
> * The preprocessor method is in:
>
> unrolled_tuple.hpp
>
> and is roughly the same as the vertical tuple implementation here:
>
>
>
http://svn.boost.org/svn/boost/sandbox/variadic_templates/sandbox/slim/test/tuple_impl_vertical.hpp
>
>
> The main difference, AFAICT, is that unrolled uses aggregation
> (via the member declaration:
>
> tuple<Tail...> tail;
>
> on line 133. In contrast, the vertical tuple uses inheritance:
>
> struct tuple_impl<Index, BOOST_PP_ENUM_PARAMS(TUPLE_CHUNK,
> TUPLE_IMPL_TYPE_NAME), Others...>
> : tuple_impl<Index+TUPLE_CHUNK, Others...>
>
> as shown on line 42 of the .hpp file.
>
[snip]
>
> * The variadic template method is in:
>
> tuple.cpp
>
> which is close to that here:
>
>
>
http://svn.boost.org/svn/boost/sandbox/variadic_templates/sandbox/slim/test/tuple_impl_horizontal.hpp
>
> in that both methods use multiple inheritance with an int key type
> paired with the tuple element type. In the case of tuple.cpp, the
> pairing is done with:
>
> template<int I, typename T>
> struct tuple_elem
>
> in tuple_impl_horizontal, pairing is done with:
>
> template<typename Key, typename Value>
> struct element
> ;
> template<int Key, typename Value>
> struct element<int_key<Key>,Value>
> {
> Value value;
> };
>
> The get functions are essentially the same.
>
[snip]
Actually, another, maybe significant difference, is the templated
CTORs in the BoostCon implementations. The sandbox/slim
implementations don't have them, relying just on the default CTOR's
for the tuple elements.

Currently in the sandbox slim/test directory:

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

there's

  tuple_impl_bcon12_horizontal.hpp
  tuple_impl_bcon12_vertical.hpp

As indicated in comments within these files, the code was copied from
files in:

  https://github.com/ericniebler/home/tree/master/src/tuple

and then slightly modified to allow use in the
tuple.benchmark.mini.cpp in the sandbox slim/test directory. The
python program in that directory was also modified to use these 2 new
implementations. The resulting test output is also in the sandbox
slim/test directory in file:

  tuple.benchmark.mini.time.txt

It shows that the bcon12 implementations:

  tuple_impl_bcon12_horizontal.hpp
  tuple_impl_bcon12_vertical.hpp

compile significantly slower than the original implementations:

  tuple_impl_horizontal.hpp
  tuple_impl_vertical.hpp

I hadn't expected that since, as mentioned above, there didn't seem to
be that much difference in the 2 implementations.

Anyone have any theories on why that's the case (I wouldn't think the
templated CTOR's would cause any slowdown since they're not used).

-regards,
Larry


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