Skip to content

@benchmark reports x5 slower with Float32 Tuple with julia 1.12 #59906

@dpinol

Description

@dpinol

@benchmark on the program below reports x5 slower (800ns vs 160ns) with Julia 1.12.1 wrt 1.11.6. Same timing if we setup tmp argument through benchmark setup argument. Tested on Ubuntu 25.04.
However, the manual @time reports the same timing in both versions.
The difference only occurs with Float32 (not with Float64, Int32 for Int64)

using BenchmarkTools

function f(tmp::Tuple{Float32, Float32})::Float32
    i = 1
    while i <= 1000
        if i % 2 == 0
            tmp = (tmp[1], tmp[2] + one(Float32))
        end
        i += 1
    end
    return tmp[1] + tmp[2]
end

function main()
    tmp = (zero(Float32), zero(Float32))
    res = 0
    @time for i in 1:10_000
        tmp = (zero(Float32), zero(Float32))
        res += f(tmp)
    end
    println(res)
    return display(@benchmark($f($tmp)))
end
main()

Julia 1.12.1

Image

Julia 1.11.6

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions