On Fri, Mar 25, 2011 at 10:49 PM, Jonathan M Davis <jmdavisp...@gmx.com> wrote: > On 2011-03-25 19:04, Caligo 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. > > It sure sounds like it didn't inline it. Did you compile with -inline? If you > didn't then it definitely won't inline it. > > - Jonathan M Davis >
I didn't know I had to supply GDC with -inline, so I did, and it did not help. In fact, with the -inline option the performance gets worse (for DMD and GDC), even for code that doesn't contain any function calls. In any case, code compiled with DMD is always behind GDC when it comes to performance.