Boost logo

Boost :

Subject: Re: [boost] Metaprogram benchmarks
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2012-04-05 02:44:36

On 04/04/2012 06:08 PM, Dave Abrahams wrote:
> on Tue Apr 03 2012, Sumant Tambe<> 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. 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.

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

Boost list run by bdawes at, gregod at, cpdaniel at, john at