# BenchmarkTools Puzzles

**URL:** <https://discourse.julialang.org/t/benchmarktools-puzzles/44993>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [August 15, 2020, 1:52pm UTC](https://discourse.julialang.org/t/benchmarktools-puzzles/44993 "2020-08-15T13:52:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawk/32/16763_2.png) [@Hawk](https://discourse.julialang.org/u/Hawk)\
**Post date:** [August 15, 2020, 1:52pm UTC](https://discourse.julialang.org/t/benchmarktools-puzzles/44993/1 "2020-08-15T13:52:56Z")

</div>

I am following Chris’s tutorial of mit18337 course, in his lecture note([Optimizing Serial Code](https://mitmath.github.io/18337/lecture2/optimizing)), there is an example about evaluating cost of heap allocation.

```julia
using LinearAlgebra, BenchmarkTools
function alloc_timer(n)
    A = rand(n,n)
    B = rand(n,n)
    C = rand(n,n)
    t1 = @belapsed $A*$B
    t2 = @belapsed mul!($C,$A,$B)
    t1,t2
end
ns = 2 .^ (2:7)
res = [alloc_timer(n) for n in ns]
alloc = [x[1] for x in res]
noalloc = [x[2] for x in res]

```

But when I changed the above piece of code like:

```julia
t1 = @belapsed A*B

```

**The system gives me an error: A not defined**

I have seen the manual([BenchmarkTools](https://github.com/JuliaCI/BenchmarkTools.jl)) of BenchmarkTools.jl, it says(hopefully my understanding is right) about the difference of with or without $:

- Having $ means we are evaluating using passing values to a function.
- Not using $ means we are using hard-coded form to evaluate

Back to my problem, I have tried using with and without $ outside a function. It works well.  
I don’t know whether is it due to the internal realization or mechanism of the package BenchmarkTools.jl, or rather myself ignoring some syntax problem?
