Really like that you have broken down all of the steps and taken the time to benchmark each of them.
Some other suggestions:
Maybe stream stdin, rather than reading the whole thing at the start? io::stdin().read_to_end(&mut buffer).ok(); feels expensive.
Perhaps pick a specialized hash function that's happy with short strings.
Maybe use Vec::with_capacity(words.len()) rather than the vec![] macro when you construct multiple and single. That'll avoid several allocations. Although it also will probably waste a lot of memory.
Im primarily interested in optimizing for runtime, but I think it would be interesting to see how the implementation differs if you optimize for space.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Really like that you have broken down all of the steps and taken the time to benchmark each of them.
Some other suggestions:
Maybe stream stdin, rather than reading the whole thing at the start?
io::stdin().read_to_end(&mut buffer).ok();
feels expensive.Perhaps pick a specialized hash function that's happy with short strings.
Maybe use
Vec::with_capacity(words.len())
rather than thevec![]
macro when you constructmultiple
andsingle
. That'll avoid several allocations. Although it also will probably waste a lot of memory.Great ideas, i'll update my code and measure.
Im primarily interested in optimizing for runtime, but I think it would be interesting to see how the implementation differs if you optimize for space.