Boost logo

Proto :

Subject: [proto] proto performance
From: Karsten Ahnert (karsten.ahnert_at_[hidden])
Date: 2011-02-20 05:46:39


Hi,

I wrote a tiny linear algebra edsl using proto and std::tr1::array:

namespace linear_algebra
{
    const size_t n = 512;
    typedef std::tr1::array< double , n > state_type;

    template<typename T > struct is_terminal : mpl::false_ {};
    template<> struct is_terminal< state_type > : mpl::true_ {};
    template<> struct is_terminal< double > : mpl::true_ {};

    BOOST_PROTO_DEFINE_OPERATORS( is_terminal , proto::default_domain )

    struct vector_context
    : proto::callable_context< vector_context const >
    {
        size_t m_i;
        vector_context( size_t i ) : m_i( i ) { }

        typedef double result_type;

        double operator()( proto::tag::terminal , state_type & arr ) const
        {
            return arr[ m_i ];
        }
    };
}

template< typename Expr >
void assign_proto( linear_algebra::state_type &x , Expr const & expr )
{
    using namespace linear_algebra;
    for( size_t i=0 ; i<n ; ++i )
    {
        vector_context ctx( i );
        x[i] = proto::eval( expr , ctx );
    }
}

I compared the run-time performance of a particular expression to its
hand written version I wonder that Proto is about 2 to 4 times slower
(depending on the size of the vectors). Is there something I can do to
enhance the performance of proto?

The full code is here http://pastebin.com/Je1JEfCN

Thanks,

Karsten


Proto list run by eric at boostpro.com