# To avoid allocations, avoid anonymous functions?

**URL:** <https://discourse.julialang.org/t/to-avoid-allocations-avoid-anonymous-functions/9458>\
**Category:** New to Julia\
**Tags:** memory-allocation\
**Created:** [March 2, 2018, 4:15pm UTC](https://discourse.julialang.org/t/to-avoid-allocations-avoid-anonymous-functions/9458 "2018-03-02T16:15:49Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 2, 2018, 4:33pm UTC](https://discourse.julialang.org/t/to-avoid-allocations-avoid-anonymous-functions/9458/4 "2018-03-02T16:33:49Z")

</div>

There is no performance penalty for anonymous functions at all (in fact, they are internally handled by the same mechanisms that handle “regular” functions). It’s just that you’re seeing measurements which are not particularly helpful because:

1. Your `f` field is un-typed (as Chris mentioned). See: [https://docs.julialang.org/en/stable/manual/performance-tips/#Avoid-fields-with-abstract-type-1](https://docs.julialang.org/en/stable/manual/performance-tips/#Avoid-fields-with-abstract-type-1)
2. You are timing in global scope. For accurate, representative benchmark results, especially for fast functions, use [GitHub - JuliaCI/BenchmarkTools.jl: A benchmarking framework for the Julia language](https://github.com/JuliaCI/BenchmarkTools.jl), e.g. `@benchmark process_x2(1.0, $myt2, 2.0)`.

---

_[View the full topic](https://discourse.julialang.org/t/to-avoid-allocations-avoid-anonymous-functions/9458)._
