-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
performanceMust go fasterMust go faster
Description
This implementation seems to be slightly faster than extrema:
function _extrema(v)
mn = mx = first(v)
@inbounds for i in firstindex(v)+1:lastindex(v)
vi = v[i]
vi < mn && (mn = vi)
mx < vi && (mx = vi)
end
mn, mx
end
@belapsed extrema(x) setup=(x=rand(Int, 10_000))
# 2.475222222222222e-6
@belapsed _extrema(x) setup=(x=rand(Int, 10_000))
# 2.0984e-6
@belapsed extrema(x) setup=(x=rand(Int, 10))
# 1.018937875751503e-8
@belapsed _extrema(x) setup=(x=rand(Int, 10))
# 7.78878878878879e-9Originally posted by @LilithHafner in #44230 (comment)
Metadata
Metadata
Assignees
Labels
performanceMust go fasterMust go faster