←back to thread

Faster Argmin on Floats

(algorithmiker.github.io)
20 points return_to_monke | 2 comments | | HN request time: 0.414s | source
Show context
TheDudeMan ◴[] No.45310426[source]
How fast if you write a for loop and keep track of the index and value of the smallest (possibly treating them as ints)?
replies(1): >>45310547 #
nine_k ◴[] No.45310547[source]
I hazard to guess that it would be the same, because the compiler would produce a loop out of .iter(), would expose the loop index via .enumerate(), and would keep track of that index in .min_by(). I suppose the lambda would be inlined, maybe even along with comparisons.

I wonder could that be made faster by using AVX instructions; they allow to find the minimum value among several u32 values, but not immediately its index.

replies(3): >>45311141 #>>45311388 #>>45311983 #
1. TinkersW ◴[] No.45311983[source]
Yes this is fairly easy to write in AVX, and you can track the index also, honestly the code is cleaner and nicer to read than this mildly obfuscated rust.
replies(1): >>45312039 #
2. imtringued ◴[] No.45312039[source]
You're referring to nothing and nothing. What exactly are you talking about? It certainly can't be the trivial to understand one liners in the blog.