On Sunday, 19 February 2017 at 20:00:00 UTC, Daniel Kozak wrote:
Dne 19.2.2017 v 20:19 berni via Digitalmars-d-learn napsal(a):
Is it possible to force a function to be inlined?
Comparing a C++ and a D program, the main difference in speed
(about 20-30%) is, because I manage to force g++ to inline a
function while I do not find any means to do the same on D.
yes
https://wiki.dlang.org/DIP56
pragma(inline, true) doesn't work out well:
int bar;
void main(string[] args)
{
if (foo()) {}
}
bool foo()
{
pragma(inline, true)
if (bar==1) return false;
if (bar==2) return false;
return true;
}
with
dmd -inline test.d
I get
test.d(8): Error: function test.foo cannot inline function
When I remove -inline, it compiles, but seems not to inline. I
cannot tell from this small example, but with the large program,
there is no speed gain.
It also compiles with -inline when I remove the "if (bar==2)...".
I guess, it's now really inlining, but the function is
ridiculously short...
I havn't tried the approach with templates yet, due to my lack of
understanding templates.