# @btime eats my variables

**URL:** https://discourse.julialang.org/t/btime-eats-my-variables/23751
**Category:** New to Julia
**Tags:** benchmarktools
**Created:** [May 1, 2019, 8:39pm UTC](https://discourse.julialang.org/t/btime-eats-my-variables/23751 "2019-05-01T20:39:12Z")
**Posts on this page:** 1
**Showing post:** 6

<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: [May 1, 2019, 10:08pm UTC](https://discourse.julialang.org/t/btime-eats-my-variables/23751/6 "2019-05-01T22:08:52Z")

</div>

Welcome!

The reason for your issue is that `@btime` is designed to operate at global scope, so any variables it references need to be globals. That doesn’t work in your case because `x` is a local, not a global variable. Fortunately, this is easy to work around: you can use `$` to interpolate the _value_ of `x` into the expression being benchmarked:

```julia
julia> function f(x)
         @btime $x^2
       end
f (generic function with 1 method)

julia> f(1)
  0.024 ns (0 allocations: 0 bytes)

```

Note also that this isn’t a general property of macros, but just a specific result of the fact that `@btime` and `@benchmark` are designed to treat all variables inside the expression you’re benchmarking as globals.

---

_[View the full topic](https://discourse.julialang.org/t/btime-eats-my-variables/23751)._
