Boost logo

Boost :

Subject: Re: [boost] Metaprogram benchmarks
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-04-05 11:55:00


on Thu Apr 05 2012, Thomas Heller <thom.heller-AT-googlemail.com> wrote:

> On 04/04/2012 06:08 PM, Dave Abrahams wrote:
>>
>> on Tue Apr 03 2012, Sumant Tambe<sutambe-AT-gmail.com> wrote:
>>
>>> Some compile-time computations can be better (faster) implemented as
>>> recursive constexpr functions. I would like to see some performance
>>> comparisons between constexpr and vanilla metaprogramming.
>> Well, yes, that's the point. The question is, what kinds of
>> computations should we try to perform in order to discover where to use
>> the new techniques?
>>
>> Do we have libraries in Boost with slow-to-compile examples that would
>> make good representative test cases?
>>
> Certainly, yes, essentially every library that uses proto/fusion/mpl
> excessively are compile time hogs.

Well, I'm asking for specifics, please. Like, a path in the Boost SVN
repository.

> I, personally, haven't come around to actually extract meaningful
> benchmarks from, for example, phoenix. One thing that immediately
> comes to my mind is whether to deferr the instantation of a template
> as long as possible, or to have it instantiated immediately. Example:
>
> template <typename T>
> struct meta_function1
> {
> typedef T type;
> };
>
> template <>
> struct meta_function1<int>
> {
> typedef int type;
> };
>
> template <typename T, typename Dummy = void>
> struct meta_function2
> {
> typedef T type;
> };
>
> template <typename Dummy>
> struct meta_function2<int, Dummy>
> {
> typedef int type;
> };
>
> The question now is: which is faster meta_function1 or meta_function2?
> Of course, in this case we won't get meaningful numbers. However, some
> claim that meta_function2 is generally faster, especially in the
> context of many full specializations.

That's a bit surprising.

In C++03 compilers, fully lazy evaluation seems to become expensive in
surprising ways that aren't yet well-understood.

http://lists.boost.org/Archives/boost/2010/07/169562.php
http://lists.boost.org/Archives/boost/att-169562/Lazy_MPL__strictness_analysis.eml

> One example where the meta_function1-style is used almost all over the
> place is fusion (in the traits for example). This is not something
> C++11 related though. However, there is still much uncertainty about
> what metaprogramming techniques are costly in C++03.

Yep.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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