Serving the Quantitative Finance Community

 
User avatar
Cuchulainn
Posts: 22926
Joined: July 16th, 2004, 7:38 am

virtual calls overhead / crtp

August 3rd, 2015, 8:24 pm

QuoteOriginally posted by: lballabioQuoteOriginally posted by: CuchulainnQuote(Also, after a while I realized that for most classes I didn't really need CRTP, templates were enough. Oh well.)For good or bad, software styles are driven by developer preferences (and prejudices.) It is not Theology. Yes, but there are constraints. Assuming you don't want virtual functions, if a method defined in the base class needs to call a method defined in the derived class (so basically, the Template Method pattern) you'll need CRTP. If not, ordinary templates are enough.What I meant with that quotation was that I thought I was in the first case, and only afterwards I realized I was in the second instead.I agree 100%. The TMP and CRTP is super-tight ship.BTW I did a TMP using C++14. BUT the 'final' main algorithm must be virtual, which sees odd.
 
User avatar
pcaspers
Topic Author
Posts: 30
Joined: June 6th, 2005, 9:49 am
Location: Germany

virtual calls overhead / crtp

August 4th, 2015, 6:01 am

QuoteOriginally posted by: lballabioNot sure I've got it---which one is 1m10? Before or after the change? Do you see any difference between 27d8ae0 and 84f3208 if you compile them both?1m10 before the change, 1m7 in the current master. Oh, I should have better compared it to 27d8ae0, that was not very bright ... I will do it in the evening ...
Last edited by pcaspers on August 3rd, 2015, 10:00 pm, edited 1 time in total.
 
User avatar
pcaspers
Topic Author
Posts: 30
Joined: June 6th, 2005, 9:49 am
Location: Germany

virtual calls overhead / crtp

August 4th, 2015, 7:56 am

QuoteOriginally posted by: CuchulainnI agree 100%. The TMP and CRTP is super-tight ship.what does TMP stand for ?
 
User avatar
Cuchulainn
Posts: 22926
Joined: July 16th, 2004, 7:38 am

virtual calls overhead / crtp

August 4th, 2015, 8:49 am

QuoteOriginally posted by: pcaspersQuoteOriginally posted by: CuchulainnI agree 100%. The TMP and CRTP is super-tight ship.what does TMP stand for ?template method pattern QuoteAssuming you don't want virtual functions, if a method defined in the base class needs to call a method defined in the derived class (so basically, the Template Method pattern) you'll need CRTP
Last edited by Cuchulainn on August 3rd, 2015, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 22926
Joined: July 16th, 2004, 7:38 am

virtual calls overhead / crtp

August 4th, 2015, 8:52 am

QuoteOriginally posted by: outrunQuoteOriginally posted by: pcaspersQuoteOriginally posted by: CuchulainnI agree 100%. The TMP and CRTP is super-tight ship.what does TMP stand for ?When is this 100% C++ functional language shipping? Anyone dare show ho to make the Template Method Pattern redundant using TMP? I'm willing to stake a small bet on it.
Last edited by Cuchulainn on August 3rd, 2015, 10:00 pm, edited 1 time in total.
 
User avatar
pcaspers
Topic Author
Posts: 30
Joined: June 6th, 2005, 9:49 am
Location: Germany

virtual calls overhead / crtp

August 4th, 2015, 12:05 pm

so TMP = template method pattern or TMP = template meta programming ? :-)
 
User avatar
Cuchulainn
Posts: 22926
Joined: July 16th, 2004, 7:38 am

virtual calls overhead / crtp

August 4th, 2015, 1:41 pm

QuoteOriginally posted by: pcaspersso TMP = template method pattern or TMP = template meta programming ? :-)The second is probably senior. The 1st is just a shorthand.
 
User avatar
pcaspers
Topic Author
Posts: 30
Joined: June 6th, 2005, 9:49 am
Location: Germany

virtual calls overhead / crtp

August 4th, 2015, 2:58 pm

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: pcaspersso TMP = template method pattern or TMP = template meta programming ? :-)The second is probably senior. The 1st is just a shorthand.I thought "template method pattern" refers to a specific design pattern. Anyway.
 
User avatar
pcaspers
Topic Author
Posts: 30
Joined: June 6th, 2005, 9:49 am
Location: Germany

virtual calls overhead / crtp

August 4th, 2015, 3:27 pm

QuoteOriginally posted by: pcaspersQuoteOriginally posted by: lballabioNot sure I've got it---which one is 1m10? Before or after the change? Do you see any difference between 27d8ae0 and 84f3208 if you compile them both?1m10 before the change, 1m7 in the current master. Oh, I should have better compared it to 27d8ae0, that was not very bright ... I will do it in the evening ...whoa, 5.4s in 27d8ae0, so factor 13the question is, why is this example running 1m7s in my current master => this is because herewe have 300 grid points instead of 50 before (is there a special reason for that ?). With 50 the running time is 3.7s.
Last edited by pcaspers on August 3rd, 2015, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 22926
Joined: July 16th, 2004, 7:38 am

virtual calls overhead / crtp

August 4th, 2015, 6:21 pm

QuoteOriginally posted by: pcaspersQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: pcaspersso TMP = template method pattern or TMP = template meta programming ? :-)The second is probably senior. The 1st is just a shorthand.I thought "template method pattern" refers to a specific design pattern. Anyway.Indeed.
 
User avatar
pcaspers
Topic Author
Posts: 30
Joined: June 6th, 2005, 9:49 am
Location: Germany

virtual calls overhead / crtp

August 5th, 2015, 5:56 am

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: pcaspersQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: pcaspersso TMP = template method pattern or TMP = template meta programming ? :-)The second is probably senior. The 1st is just a shorthand.I thought "template method pattern" refers to a specific design pattern. Anyway.Indeed.But template meta programming does not.
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

virtual calls overhead / crtp

August 5th, 2015, 7:08 am

Yes. There's no relation between Template Method Pattern (which, BTW, doesn't even involve templates) and template metaprogramming. It's just unfortunate that they share the same initials. TMP usually refers to the second.
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

virtual calls overhead / crtp

August 5th, 2015, 7:11 am

And yes, I remembered a performance gain around 10x, so the 13x factor you measured agrees with that.