[proto] proto performance
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; templatetypename 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 ; in ; ++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 mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto
Re: [proto] proto performance
On 2/20/2011 5:52 PM, Joel Falcou wrote: 1/ how do you measure performances ? Anything which is not the median of 1-5K runs is meaningless. You can see how he measures it in the code he posted. 2/ Don't use context, transform are usually better optimized by compilers That really shouldn't matter. 3/ are you using gcc on a 64 bits system ? On this configuration a gcc bug prevent proto to be inlined. Naive question: are you actually compiling with optimizations on? -O3 -DNDEBUG? And are you sure the compiler isn't lifting the whole thing out of the loop, since the computation is the same with each iteration? -- Eric Niebler BoostPro Computing http://www.boostpro.com signature.asc Description: OpenPGP digital signature ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto
Re: [proto] proto performance
On 20/02/11 11:57, Eric Niebler wrote: On 2/20/2011 5:52 PM, Joel Falcou wrote: 1/ how do you measure performances ? Anything which is not the median of 1-5K runs is meaningless. You can see how he measures it in the code he posted. I clicked send too fast :p 2/ Don't use context, transform are usually better optimized by compilers That really shouldn't matter. Well, in our test it does. At least back in gcc 4.4 3/ are you using gcc on a 64 bits system ? On this configuration a gcc bug prevent proto to be inlined. Naive question: are you actually compiling with optimizations on? -O3 -DNDEBUG? And are you sure the compiler isn't lifting the whole thing out of the loop, since the computation is the same with each iteration? Oh yeah I forgot these. On my machine (mac osx dual core intel with g++4-5) i have a 25% speed up by proto ... ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto
Re: [proto] proto performance
On 20/02/11 11:55, Karsten Ahnert wrote: On 02/20/2011 11:57 AM, Eric Niebler wrote: It gcc 4.4 on a 64bit machine. Of course, I compile with -O3. Ding! welcome to gcc-4.4 64bits compiler hellfest. Try 4.5, 4.4 64bits can't inlien for w/e reason. ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto
Re: [proto] proto performance
On 02/20/2011 12:02 PM, Joel Falcou wrote: On 20/02/11 11:55, Karsten Ahnert wrote: On 02/20/2011 11:57 AM, Eric Niebler wrote: It gcc 4.4 on a 64bit machine. Of course, I compile with -O3. Ding! welcome to gcc-4.4 64bits compiler hellfest. Try 4.5, 4.4 64bits can't inlien for w/e reason. Great, I tried with gcc 4.5 and the proto part is now around 5-10 percents faster. Thank you. ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto -- Dr. Karsten Ahnert Ambrosys GmbH - Gesellschaft für Management komplexer Systeme Geschwister-Scholl-Str. 63a D-14471 Potsdam Tel: +4917682001688 Fax: +493319791300 Ambrosys GmbH - Gesellschaft für Management komplexer Systems Gesellschaft mit beschränkter Haftung Sitz der Gesellschaft: Geschwister-Scholl-Str. 63a, 14471 Potsdam Registergericht: Amtsgericht Potsdam, HRB 21228 P Geschäftsführer: Dr. Karsten Ahnert, Dr. Markus Abel ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto
Re: [proto] proto performance
On 02/20/2011 12:08 PM, Joel Falcou wrote: On 20/02/11 12:03, Karsten Ahnert wrote: On 02/20/2011 12:02 PM, Joel Falcou wrote: On 20/02/11 11:55, Karsten Ahnert wrote: On 02/20/2011 11:57 AM, Eric Niebler wrote: It gcc 4.4 on a 64bit machine. Of course, I compile with -O3. Ding! welcome to gcc-4.4 64bits compiler hellfest. Try 4.5, 4.4 64bits can't inlien for w/e reason. Great, I tried with gcc 4.5 and the proto part is now around 5-10 percents faster. Thank you. We banged our heads for weeks on this issue earlier until we found some dubious bug report in gcc bugzilla flagged as nofix :/ Seems the 4.5 branch solved it somehow. It is amazing that the proto expression is faster then the naive one. The compiler must really love the way proto evaluates an expression. You cna also try compiling with 4.4 using -m32 ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto -- Dr. Karsten Ahnert Ambrosys GmbH - Gesellschaft für Management komplexer Systeme Geschwister-Scholl-Str. 63a D-14471 Potsdam Tel: +4917682001688 Fax: +493319791300 Ambrosys GmbH - Gesellschaft für Management komplexer Systems Gesellschaft mit beschränkter Haftung Sitz der Gesellschaft: Geschwister-Scholl-Str. 63a, 14471 Potsdam Registergericht: Amtsgericht Potsdam, HRB 21228 P Geschäftsführer: Dr. Karsten Ahnert, Dr. Markus Abel ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto
Re: [proto] proto performance
On 2/20/2011 6:40 PM, Joel Falcou wrote: On 20/02/11 12:31, Karsten Ahnert wrote: It is amazing that the proto expression is faster then the naive one. The compiler must really love the way proto evaluates an expression. I still dont really know why. Usual speed-up in our use cases here is like ranging from 10 to 50%. That's weird. -- Eric Niebler BoostPro Computing http://www.boostpro.com ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto
Re: [proto] proto performance
On 20/02/11 12:41, Eric Niebler wrote: On 2/20/2011 6:40 PM, Joel Falcou wrote: On 20/02/11 12:31, Karsten Ahnert wrote: It is amazing that the proto expression is faster then the naive one. The compiler must really love the way proto evaluates an expression. I still dont really know why. Usual speed-up in our use cases here is like ranging from 10 to 50%. That's weird. Well, for me it's weird in the good way so I dont complain. Old version of nt2 had cases where we were thrice as fast as same vector+iterator based code ... ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto