# Faster \`findmin\` without LoopVectorization.jl

**URL:** <https://discourse.julialang.org/t/faster-findmin-without-loopvectorization-jl/121742>\
**Category:** Performance\
**Tags:** question\
**Created:** [October 25, 2024, 10:04am UTC](https://discourse.julialang.org/t/faster-findmin-without-loopvectorization-jl/121742 "2024-10-25T10:04:11Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Post date:** [October 25, 2024, 5:53pm UTC](https://discourse.julialang.org/t/faster-findmin-without-loopvectorization-jl/121742/3 "2024-10-25T17:53:30Z")

</div>

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:

```julia
function naive_findmin(w, N...)
    x = @fastmath foldl(min, w)
    i = findfirst(==(x), w)::Int
    x, i
end

```

On my machine I get

```julia
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`.

---

_[View the full topic](https://discourse.julialang.org/t/faster-findmin-without-loopvectorization-jl/121742)._
