While working on large arrays (images) searching for the fastest min/max and extrema I struggled to findout that recent fast minimum and maximum implementation use reduce. However extrema can be improved
julia> versioninfo()
Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) E-2186M CPU @ 2.90GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 6
julia> x=rand(Float32,1000000);
julia> @btime extrema($x)
2.187 ms (0 allocations: 0 bytes)
(5.9604645f-7, 0.9999994f0)
julia> function minmax(x)
"""
Find min and max values in an Array, 3x faster than extrema
"""
a = b = x[1]
for i in 2:length(x)
if x[i] > b
b = x[i]
elseif x[i] < a
a = x[i]
end
end
a, b
end
minmax (generic function with 1 method)
julia> @btime minmax($x)
681.715 μs (0 allocations: 0 bytes)
(5.9604645f-7, 0.9999994f0)
Hope it can be of some use