# Call overhead of keyword args

**URL:** <https://discourse.julialang.org/t/call-overhead-of-keyword-args/17380>\
**Category:** General Usage\
**Created:** [November 10, 2018, 8:49am UTC](https://discourse.julialang.org/t/call-overhead-of-keyword-args/17380 "2018-11-10T08:49:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [November 10, 2018, 8:49am UTC](https://discourse.julialang.org/t/call-overhead-of-keyword-args/17380/1 "2018-11-10T08:49:57Z")

</div>

I was reading  
[https://docs.julialang.org/en/v1/manual/performance-tips/index.html#Declare-types-of-keyword-arguments-1](https://docs.julialang.org/en/v1/manual/performance-tips/index.html#Declare-types-of-keyword-arguments-1)

I could not really follow what is said there (“Functions with keyword arguments have near-zero overhead for call sites that pass only positional arguments.”) Is there a call overhead to a simple  
`f(x, val = y)` compared to `f(x,y)`?

A small experiment suggest not:

```julia
f(x) = x+1

g(f, x, n) = let y = x; for i in 1:n; y = f(y); end; y end

f2(x;y=x) = f(y)
g2(f2, x, n) = let y = x; for i in 1:n; y = f2(y; y=y); end; y end

```

```julia
julia> @btime g(f, 1, 10_000)
  5.091 ns (0 allocations: 0 bytes)
10001

julia> @btime g2(f2, 1, 10_000)
  5.096 ns (0 allocations: 0 bytes)
10001

```

Or is this maybe to simple to trigger a problem.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [November 10, 2018, 10:17am UTC](https://discourse.julialang.org/t/call-overhead-of-keyword-args/17380/2 "2018-11-10T10:17:29Z")

</div>

I think that section is no longer relevant, since it stems from a time when keyword arguments were indeed slower because they were not yet implemented using `NamedTuple`s ([https://github.com/JuliaLang/julia/pull/24795](https://github.com/JuliaLang/julia/pull/24795)). See [https://github.com/JuliaLang/julia/pull/24987](https://github.com/JuliaLang/julia/pull/24987) for the proposed removal of that section.

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [November 10, 2018, 8:13pm UTC](https://discourse.julialang.org/t/call-overhead-of-keyword-args/17380/3 "2018-11-10T20:13:15Z")

</div>

I’ve seen this so many times now on this forum – Please whenever you get timings in the low nanoseconds, be very suspicious! A 3 GHz CPU executes 3 clock cycles in 1 ns, so 5 ns means ~15 clock cycles, which is not a lot of time, and obviously not enough to iterate 10,000 times. It most likely means that either the compiler is clever enough to eliminate/pre-calculate the for loop, or the expression executes too quickly for the timing to work correctly.
