# Save dispatched function for later call

**URL:** <https://discourse.julialang.org/t/save-dispatched-function-for-later-call/67218>\
**Category:** General Usage\
**Created:** [August 28, 2021, 12:51pm UTC](https://discourse.julialang.org/t/save-dispatched-function-for-later-call/67218 "2021-08-28T12:51:00Z")\
**Posts on this page:** 1\
**Showing post:** 22

<div class="post-metadata">

**Author:** ![Marcell\_Havlik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcell_havlik/32/37424_2.png) [@Marcell\_Havlik](https://discourse.julialang.org/u/Marcell_Havlik)\
**Post date:** [August 30, 2021, 8:45pm UTC](https://discourse.julialang.org/t/save-dispatched-function-for-later-call/67218/22 "2021-08-30T20:45:07Z")

</div>

I have only one observation yet to note.

If I compare speeds:

```julia

function l(ops, a, b)
	for op in ops
		op(a,b)
	end
end

a=4
b=7
ops_s=[:ADD, :ADD, :MUL, :ADD, :SUBS, :SUBS, :MUL, :MUL]
opp=[+, +, *, +, -, -, *, *]
w_op=[FunctionWrapper{Int, Tuple{Int, Int}}(op) for op in opp]

@btime $l($opp, $a, $b)
@btime $l($w_op, $a, $b)

function h(ops, a, b)
	for op in ops
		if op == :ADD
			+(a, b)
		elseif op == :SUBS
			-(a, b)
		elseif op == :MUL
			*(a, b)
		elseif op == :DIV
			/(a, b)
		end
	end
end
@btime $h($ops_s, $a, $b)

```

The results:

```julia
   155.907 ns (0 allocations: 0 bytes)
   40.175 ns (0 allocations: 0 bytes)
   3.876 ns (0 allocations: 0 bytes)

```

I notice we do at least 2,3 more if in the case of h(…) functon calls and it is sort of scaling linearly with the type of operation calls. But we still get a fairly better speed, do we have still some speed lose during the FunctionWrapper calls?

`h(...)` is a compilable function, that is why it is really fast I know… but isn’t the `i(...)` with the wrapped version should be fine? Where do we lose speed with the FunctionWrapper version? Shouldn’t it be comparable in speed?

---

_[View the full topic](https://discourse.julialang.org/t/save-dispatched-function-for-later-call/67218)._
