Skip to content

Conversation

KristofferC
Copy link
Member

fixes #59804

From #59804:

function norm_me_base(V)
    return sqrt(V[1]^2 + V[2]^2 + V[3]^2)
end

@fastmath function norm_me_fast(V)
    return sqrt(V[1]^2 + V[2]^2 + V[3]^2)
end

function norm_me_base_ntimes(V, n::Int)
    y = 0.0
    for i = 1:n
        y += norm_me_base(V)
    end
    return y
end

function norm_me_fast_ntimes(V, n::Int)
    y = 0.0
    for i = 1:n
        y += norm_me_fast(V)
    end
    return y
end

using BenchmarkTools
using StaticArrays

function benchmark_that()
	v = SVector{3}(10.567, 5.4, 2.28)
	@btime norm_me_base($v)
	@btime norm_me_fast($v)
	@btime norm_me_base_ntimes($v, 1000)
	@btime norm_me_fast_ntimes($v, 1000)
end

1.11:

julia> benchmark_that()
  1.500 ns (0 allocations: 0 bytes)
  1.500 ns (0 allocations: 0 bytes)
  380.951 ns (0 allocations: 0 bytes)
  381.158 ns (0 allocations: 0 bytes)

1.12:

julia> benchmark_that()
  1.541 ns (0 allocations: 0 bytes)
  6.958 ns (0 allocations: 0 bytes)
  381.188 ns (0 allocations: 0 bytes)
  8.181 μs (0 allocations: 0 bytes)

PR:

julia> benchmark_that()
  1.541 ns (0 allocations: 0 bytes)
  1.500 ns (0 allocations: 0 bytes)
  381.632 ns (0 allocations: 0 bytes)
  381.360 ns (0 allocations: 0 bytes)

@KristofferC KristofferC added the backport 1.12 Change should be backported to release-1.12 label Oct 13, 2025
@oscardssmith oscardssmith added performance Must go faster maths Mathematical functions labels Oct 13, 2025
@KristofferC KristofferC merged commit 354c575 into master Oct 13, 2025
9 of 11 checks passed
@KristofferC KristofferC deleted the kc/inline_pow branch October 13, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.12 Change should be backported to release-1.12 maths Mathematical functions performance Must go faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in pow_fast

2 participants