digitalmars.D.learn - inline functions
- Caligo (11/11) Mar 25 2011 T[3] data;
- Steven Schveighoffer (8/20) Mar 28 2011 ref parameters used to make functions not be inlined, but apparently tha...
T[3] data; T dot(const ref Vector o){ return data[0] * o.data[0] + data[1] * o.data[1] + data[2] * o.data[2]; } T LengthSquared_Fast(){ return data[0] * data[0] + data[1] * data[1] + data[2] * data[2]; } T LengthSquared_Slow(){ return dot(this); } The faster LengthSquared() is twice as fast, and I've test with GDC and DMD. Is it because the compilers don't inline-expand the dot() function call? I need the performance, but the faster version is too verbose.
Mar 25 2011
On Fri, 25 Mar 2011 22:04:20 -0400, Caligo <iteronvexor gmail.com> wrote:T[3] data; T dot(const ref Vector o){ return data[0] * o.data[0] + data[1] * o.data[1] + data[2] * o.data[2]; } T LengthSquared_Fast(){ return data[0] * data[0] + data[1] * data[1] + data[2] * data[2]; } T LengthSquared_Slow(){ return dot(this); } The faster LengthSquared() is twice as fast, and I've test with GDC and DMD. Is it because the compilers don't inline-expand the dot() function call? I need the performance, but the faster version is too verbose.ref parameters used to make functions not be inlined, but apparently that was fixed: http://d.puremagic.com/issues/show_bug.cgi?id=2008 The best thing to do is check the disassembly to see if the call is being inlined. Also, if you want more help besides guessing, a complete working program is good to have. -Steve
Mar 28 2011