# @btime with local function --\> not defined

**URL:** <https://discourse.julialang.org/t/btime-with-local-function-not-defined/10204>\
**Category:** Performance\
**Created:** [April 6, 2018, 7:50pm UTC](https://discourse.julialang.org/t/btime-with-local-function-not-defined/10204 "2018-04-06T19:50:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [April 6, 2018, 7:50pm UTC](https://discourse.julialang.org/t/btime-with-local-function-not-defined/10204/1 "2018-04-06T19:50:53Z")

</div>

dear J wizards—how do I use @btime inside a function with a passed argument?

```julia
julia> function testme( afun ); @btime begin afun(2) end end
testme (generic function with 1 method)

julia> testme( println )
ERROR: UndefVarError: afun not defined

```

`@atime` works, but afaik, it is not recommended for benchmarking.

---

<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:** [April 6, 2018, 8:07pm UTC](https://discourse.julialang.org/t/btime-with-local-function-not-defined/10204/2 "2018-04-06T20:07:19Z")

</div>

With interpolation, just like any other argument:

```julia
function testme(afun)
    @btime $afun(2) 
end

```

```julia
julia> f = x -> 2x
(::#36) (generic function with 1 method)

julia> testme(f)
  1.645 ns (0 allocations: 0 bytes)
4

```

---

<div class="post-metadata">

**Author:** ![sim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sim/32/22207_2.png) [@sim](https://discourse.julialang.org/u/sim)\
**Post date:** [December 12, 2022, 3:22pm UTC](https://discourse.julialang.org/t/btime-with-local-function-not-defined/10204/3 "2022-12-12T15:22:57Z")

</div>

Could someone explain what happens here ?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 12, 2022, 4:06pm UTC](https://discourse.julialang.org/t/btime-with-local-function-not-defined/10204/4 "2022-12-12T16:06:13Z")

</div>

The problem is that macros are resolved at parse time so if you have

```julia
function testme(afun)
    @btime afun(2) 
end

```

then `@btime` can only see the name `afun` but not what it refers to.
