-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
performanceMust go fasterMust go fasterregressionRegression in behavior compared to a previous versionRegression in behavior compared to a previous version
Description
This originates from JuliaArrays/OffsetArrays.jl#136 (comment)
function overflow_check(r, offset::T) where T
if offset > 0 && last(r) > typemax(T) - offset
throw(ArgumentError("Boundary overflow detected: offset $offset should be equal or less than $(typemax(T) - last(r))"))
end
end
function overflow_check_with_func(r, offset::T) where T
throw_overflow_error() = throw(ArgumentError("Boundary overflow detected: offset $offset should be equal or less than $(typemax(T) - last(r))"))
if offset > 0 && last(r) > typemax(T) - offset
throw_overflow_error()
end
endThese two works equivalently, but their performance is slightly different:
julia> r, offset = -3:3, -4;
julia> @btime overflow_check($r, $offset)
4.801 ns (0 allocations: 0 bytes) # 1.6.0-DEV.883
4.078 ns (0 allocations: 0 bytes) # 1.4.0, 1.5.1
julia> @btime overflow_check_with_func($r, $offset)
3.765 ns (0 allocations: 0 bytes) # 1.6.0-DEV.883
1.696 ns (0 allocations: 0 bytes) # 1.5.1
1.919 ns (0 allocations: 0 bytes) # 1.4.0I'm really unsure what an appropriate title should be, please rename it if that's unclear.
timholy, Moelf and JeffBezanson
Metadata
Metadata
Assignees
Labels
performanceMust go fasterMust go fasterregressionRegression in behavior compared to a previous versionRegression in behavior compared to a previous version