# How to apply a small anonymous function defined in a yaml file?

**URL:** <https://discourse.julialang.org/t/how-to-apply-a-small-anonymous-function-defined-in-a-yaml-file/126874>\
**Category:** General Usage\
**Tags:** yaml, anonymous-function\
**Created:** [March 12, 2025, 3:09pm UTC](https://discourse.julialang.org/t/how-to-apply-a-small-anonymous-function-defined-in-a-yaml-file/126874 "2025-03-12T15:09:50Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [March 13, 2025, 12:20pm UTC](https://discourse.julialang.org/t/how-to-apply-a-small-anonymous-function-defined-in-a-yaml-file/126874/11 "2025-03-13T12:20:05Z")

</div>

Update: yes it seems that the difference was that RuntimeGeneratedFunctions.jl was caching the expressions it evaled, making it seem faster than it really was in a `@btime` loop.

Here’s a macrobenchmark that avoids the caching:

```julia
function bench(f, x)
    ops = ["/", "*", "+", "-"]
    vals = rand(5)
    for op1 ∈ ops, op2 ∈ ops
        for y ∈ vals, z ∈ vals
            s = "(x) -> x $op1 $y $op2 $z" 
            f(s, x)
        end
    end
end

```

```julia
julia> @time bench(apply_eval, 1.0)
  1.077235 seconds (449.57 k allocations: 20.770 MiB, 82.07% compilation time)

julia> @time bench(apply_rgf, 1.0)
  1.115373 seconds (976.42 k allocations: 45.832 MiB, 0.66% gc time, 97.86% compilation time)

julia> @time bench(apply_interp, 1.0)
  0.111546 seconds (138.85 k allocations: 6.111 MiB)

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-apply-a-small-anonymous-function-defined-in-a-yaml-file/126874)._
