I may be missing something, but the following naive approach seem to be faster than basic_findmin
, at least for vectors that are not too long:
function naive_findmin(w, N...)
x = @fastmath foldl(min, w)
i = findfirst(==(x), w)::Int
x, i
end
On my machine I get
julia> N = 300; v = rand(N);
julia> @b basic_findmin($v, $N)
322.393 ns
julia> @b naive_findmin($v)
133.571 ns
EDIT: The timing for naive_findmin
depends on where the the minimum is. However, it seems to be always faster that basic_findmin
.