Skip to content

Clarify global variable interpolation in benchmarking. #133

@nathanrboyer

Description

@nathanrboyer

I've never understood why benchmarking requires interpolation, but running the code normally doesn't. I don't think the explanation here was satisfactory. Hoping someone can rework this sentence to explain a little better.

"Additionally, by using $ to interpolate external values, you remove the overhead caused by global variables."

julia> using BenchmarkTools

julia> @btime sum_abs(v);
98.725 ns (1 allocation: 16 bytes)

julia> @btime sum_abs($v);
60.469 ns (0 allocations: 0 bytes)

It's especially confusing given the earlier statement:

"Typically, the most common beginner pitfall is the use of untyped global variables without passing them as arguments."

In the example, v is clearly passed as an argument, so I don't see why there is suddenly a performance issue.


Also, apparently Chairmarks.jl drops the need to interpolate, so maybe the entire benchmarking section would be clearer if flipped to show examples with Chairmarks.jl and just mention BenchmarkTools.jl as the alternative option?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions