I am refactoring an API so I thought I would revisit this issue as keyword arguments would be very convenient.
The following compares positional and keyword arguments and NamedTuples.
using BenchmarkTools
pos(x) = exp(x)
kw(; x) = exp(x)
nt(y) = exp(y.x)
g_pos(x) = pos(x)
g_kw(x) = kw(x = x)
g_nt(x) = nt((x = x, ))
x = 2.5
@btime g_pos($x)
@btime g_kw($x)
@btime g_nt($x)
with the output
julia> @btime g_pos($x)
0.026 ns (0 allocations: 0 bytes)
12.182493960703473
julia> @btime g_kw($x)
8.892 ns (0 allocations: 0 bytes)
12.182493960703473
julia> @btime g_nt($x)
0.026 ns (0 allocations: 0 bytes)
12.182493960703473
julia> VERSION
v"1.2.0-DEV.17"
I am inclined to believe that something weird is going on with the benchmarking of the positional and NamedTuple arguments, since that sub-nanosecond timing is too good to believe. Any suggestions how to do it better?