Julia - how does @inline work? When to use function vs. macro? : <p>I have many small functions I would like to inline, for example to test flags for some condition:</p>

<pre><code>const COND = UInt(1&lt;&lt;BITS_FOR_COND)
function is_cond(flags::UInt)
    return flags &amp; COND != 0
end
</code></pre>

<p>I could also make a macro: </p>

<pre><code>macro IS_COND(flags::UInt)
    return :(flags &amp; COND != 0)
end
</code></pre>

<p>My motivation is many similar macro functions in the C code I am working with:</p>

<pre><code>#define IS_COND(flags) ((flags) &amp; COND)
</code></pre>

<p>I repeatedly timed the function, macro, function defined with @inline, and the expression by itself, but none are consistently faster than the others across many runs.  The generated code for the function call in 1) and 3) are much longer than for the expression in 4), but I don't know how to compare 2) since <code>@code_llvm</code> etc. don't work on other macros.</p>

<pre><code>1) for j=1:10 @time for i::UInt=1:10000 is_cond(i); end end
2) for j=1:10 @time for i::UInt=1:10000 @IS_COND(i); end end
3) for j=1:10 @time for i::UInt=1:10000 is_cond_inlined(i); end end
4) for j=1:10 @time for i::UInt=1:10000 i &amp; COND != 0; end end
</code></pre>

<p>Questions: What is the purpose of <code>@inline</code>?  I see from the sparse documentation that it appends the symbol <code>:inline</code> to the expression <code>:meta</code>, but what does that do, exactly?  Is there any reason to prefer a function or macro for this kind of task?</p>

<p>My understanding is that a C macro function just substitutes the literal text of the macro at compile time, so the resulting code has no jumps and is therefore more efficient than a regular function call.  (Safety is another issue, but let's assume the programmers know what they're doing.)  A Julia macro has intermediate steps like parsing its arguments, so it's not obvious to me whether 2) should be faster than a 1).  Ignoring for the moment that in this case the difference in performance is negligible, what technique results in the most efficient code?</p>
