Skip to content

Compiler optimization example outdated? #298

@johannes-fischer

Description

@johannes-fischer

I was just trying to get a feeling for which expressions the compiler optimizes away, to not get wrong timings. When running the example in the docs, it seems it is not optimized away by the compiler anymore:

On Julia 1.8.4:

julia> a = 1; b = 2;

julia> @btime $a + $b
  2.660 ns (0 allocations: 0 bytes)
3

julia> @btime $(Ref(a))[] + $(Ref(b))[]
  2.455 ns (0 allocations: 0 bytes)
3

julia> @btime 3
  1.450 ns (0 allocations: 0 bytes)
3

On Julia 1.7.3:

julia> a = 1; b = 2
2

julia> a = 1; b = 2;

julia> @btime $a + $b
  1.451 ns (0 allocations: 0 bytes)
3

julia> @btime $(Ref(a))[] + $(Ref(b))[]
  1.451 ns (0 allocations: 0 bytes)
3

julia> @btime 3
  0.023 ns (0 allocations: 0 bytes)
3

Does the compiler not anymore optimize code away in @btime? Or is the trick with referencing and de-referencing not working anymore?

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