# Performance of functions returned from container

**URL:** <https://discourse.julialang.org/t/performance-of-functions-returned-from-container/3747>\
**Category:** General Usage\
**Created:** [May 16, 2017, 2:16pm UTC](https://discourse.julialang.org/t/performance-of-functions-returned-from-container/3747 "2017-05-16T14:16:40Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 16, 2017, 3:10pm UTC](https://discourse.julialang.org/t/performance-of-functions-returned-from-container/3747/3 "2017-05-16T15:10:31Z")

</div>

[https://github.com/yuyichao/FunctionWrappers.jl](https://github.com/yuyichao/FunctionWrappers.jl)

```julia
import FunctionWrappers: FunctionWrapper

using BenchmarkTools
const F64IntFunc = FunctionWrapper{Float64,Tuple{Int}}

const dict = Vector{F64IntFunc}(4);

const cdict = Int[1, 2, 3, 4]

f1(x::Int) = 1 + x
dict[1] = F64IntFunc(f1);

f2(x::Int) = 1 - x
dict[2] = F64IntFunc(f2);

f3(x::Int) = 1.0/x
dict[3] = F64IntFunc(f3);

f4(x::Int) = x << 1
dict[4] = F64IntFunc(f4);

ref = @benchmarkable begin
    a1, a2 = cdict[1], cdict[2]
    f1(a1), f2(a2)
end

test = @benchmarkable begin
    dict[1](1), dict[2](2)
end

run(ref)
run(test)

```

```julia
julia> run(ref)
BenchmarkTools.Trial: 
  memory estimate: 0 bytes
  allocs estimate: 0
  --------------
  minimum time: 20.000 ns (0.00% GC)
  median time: 30.000 ns (0.00% GC)
  mean time: 30.841 ns (0.00% GC)
  maximum time: 11.913 μs (0.00% GC)
  --------------
  samples: 10000
  evals/sample: 1

julia> run(test)
BenchmarkTools.Trial: 
  memory estimate: 0 bytes
  allocs estimate: 0
  --------------
  minimum time: 24.000 ns (0.00% GC)
  median time: 37.000 ns (0.00% GC)
  mean time: 40.765 ns (0.00% GC)
  maximum time: 11.749 μs (0.00% GC)
  --------------
  samples: 10000
  evals/sample: 1

```

Ran on 0.5. Seems to be some ambiguity problems on 0.6 but should be easily fixed in the package.

---

_[View the full topic](https://discourse.julialang.org/t/performance-of-functions-returned-from-container/3747)._
