What does the beckmarking in global scope mean?

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?

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

Check out this previous thread and the linked SO answer

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.

2 Likes

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?

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

1 Like

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?

Yes. The global keyword only matters for code like

foo()
    global x
    x = 5
end

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

1 Like
  • 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?

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?