Keyword versus positional arguments

Reviewing @avik Sengupta’s book «Julia High Performance» 2nd edition, it says that performance of functions with positional arguments is better than those with keyword (named) arguments, giving the following example:

using BenchmarkTools
named_param(x; y=1, z=1) = x^y + x^z
pos_param(x,y,z) = x^y + x^z
@btime named_param(4; y=2, z=3)
@btime pos_param(4, 2, 3)

Sengupta’s book reports 8.306ns for named_param and 5.548ns for pos_param:

kwargs1

but running the same code in my own computer I get the opposite:

Any explanation for this?

That advise was correct until 1.0 (technically 0.7), but is thankfully no longer true.

5 Likes

As far as I remember, all the code in the book was tested in 1.0. However, this difference was so narrow, that it wouldn’t surprise me if it has changed since.

1 Like