The goal of BenchmarkTools is to assess the runtime of a function as though it were written that way inside another function. The trouble is that when you write sin(x)
, it’s not clear whether x
is a global (and slow, see the very first bullet of the [performance tips]) or a local variable. The special $
flag is how BenchmarkTools can distinguish these two cases. The same thing goes when you write sin(0.5)
— that 0.5 could be a hard-coded constant (and eligible for constant propagation) or a random choice of a variable.
As far as what the cost will be when running from the REPL, if you can see the difference between 20ns and 5ns, I’ve got a bridge to sell you. The true latency there is more impacted by the amount of time it takes to hit enter, parse, eval, and print than the actual computation.