# What does the beckmarking in global scope mean?

**URL:** <https://discourse.julialang.org/t/what-does-the-beckmarking-in-global-scope-mean/80898>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 11, 2022, 4:34pm UTC](https://discourse.julialang.org/t/what-does-the-beckmarking-in-global-scope-mean/80898 "2022-05-11T16:34:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [May 11, 2022, 4:34pm UTC](https://discourse.julialang.org/t/what-does-the-beckmarking-in-global-scope-mean/80898/1 "2022-05-11T16:34:46Z")

</div>

Hello,  
I have some issues that I did n’t get them well.  
1- Why when using ·@btime, it is needed to used `$` before the parameters?  
2- Are `A` and `B`. below constant or non-constant variables?

```julia
A = randn(3,3); b = randn(3);
julia> @btime A\b
julia> @btime $A\$b

```

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [May 11, 2022, 4:45pm UTC](https://discourse.julialang.org/t/what-does-the-beckmarking-in-global-scope-mean/80898/2 "2022-05-11T16:45:44Z")

</div>

Check out this previous thread and the linked SO answer

> [@Function calls in global scope, benchmarking, etc](https://discourse.julialang.org/t/function-calls-in-global-scope-benchmarking-etc/27513/):
>
> I recently asked a [Stack Overflow question](https://stackoverflow.com/questions/57314092/when-to-interpolate-in-benchmarking-expressions) about interpolating into benchmarking expressions. But I still have some lingering confusion about the impact on performance of passing global variables as arguments to functions. The Julia manual in the Performance Tips section says A global variable might have its value, and therefore its type, change at any point. This makes it difficult for the compiler to optimize code using global variables. Variables should be local, or passed as arguments to f…

In your example, `$` is used to get a sense of the performance of `A\b` when `A` and `b` are _either_ local and type-stable inside a function (including if they’re arguments) _or_ they’re declared as `const` globals. It’s the former that most folks are interested in when benchmarking because that’s the happy path for high-performance Julia.

You’ve not declared `A` and `b` as `const`, so they’re not constant.

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [May 11, 2022, 5:06pm UTC](https://discourse.julialang.org/t/what-does-the-beckmarking-in-global-scope-mean/80898/3 "2022-05-11T17:06:10Z")

</div>

Thanks for your reference.

So, `A` and `B` are not const. Are they global? As far as I know, they are not global because no `global` word is put in front of them, correct?

---

<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:** [May 11, 2022, 5:08pm UTC](https://discourse.julialang.org/t/what-does-the-beckmarking-in-global-scope-mean/80898/4 "2022-05-11T17:08:15Z")

</div>

they are global. Any variable that isn’t declared in a scope (i.e. a function or let block) is global.

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [May 11, 2022, 5:11pm UTC](https://discourse.julialang.org/t/what-does-the-beckmarking-in-global-scope-mean/80898/5 "2022-05-11T17:11:01Z")

</div>

I see.  
so the benefit of using the keyword `global` in front of a variable is to let it be seen (global) out of its scope, right?

---

<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:** [May 11, 2022, 5:16pm UTC](https://discourse.julialang.org/t/what-does-the-beckmarking-in-global-scope-mean/80898/6 "2022-05-11T17:16:15Z")

</div>

Yes. The `global` keyword only matters for code like

```julia
foo()
    global x
    x = 5
end

```

since otherwise `x=5` would define a new local variable.

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [May 11, 2022, 5:41pm UTC](https://discourse.julialang.org/t/what-does-the-beckmarking-in-global-scope-mean/80898/7 "2022-05-11T17:41:54Z")

</div>

> [@Function calls in global scope, benchmarking, etc](https://discourse.julialang.org/t/function-calls-in-global-scope-benchmarking-etc/27513/4):
>
> Ah, I see where the disconnect is. The 4x difference you’re seeing in sin isn’t really a 4x multiple. It’s a ~constant 15ns. In that 15ns, Julia looks up the method table for sin, figures out which method to dispatch to, then calls the appropriate sin(::Float64). The remaining 5ns is actually doing the computation of the sine. If you have a heavy duty computation, calling it from global scope isn’t going to make it run 4x slower. It’ll make it run 15ns slower. The time it takes to do dyna…

- So, this `15ns` is actually consumed during the compilation stage not during the run-time, and since the performance matters during runt-time, so `$` is used, correct?

> [@Function calls in global scope, benchmarking, etc](https://discourse.julialang.org/t/function-calls-in-global-scope-benchmarking-etc/27513/2):
>
> The goal of BenchmarkTools is to assess the runtime of a function as though it were written that way inside another function. The trouble is that when you write sin(x), it’s not clear whether x is a global (and slow, see the very first bullet of the [performance tips]) or a local variable. The special $ flag is how BenchmarkTools can distinguish these two cases. The same thing goes when you write sin(0.5) — that 0.5 could be a hard-coded constant (and eligible for constant propagation) or a r…

How can the BenchmarkTools distinguish between these two cases? Does it start to check the performance after the compilation stage is finished, at which the case (type) of variables is known?
