3 ms·
The problem with the Julia version is just that it collects a word to a list of characters every time it calls match-constraint. Removing that one line makes th
by adgjlsfhk1 5y ago
The problem with the Julia version is just that it collects a word to a list of characters every time it calls match-constraint. Removing that one line makes the Julia version 5x faster.
function match_constraint(word::String, constraint::Constraint)::Bool
if constraint.type == has_no
constraint.letter ∉ word
elseif constraint.type == has_but_not_at
(constraint.letter ∈ word) && (word[constraint.index] != constraint.letter)
elseif constraint.type == has_at
word[constraint.index] == constraint.letter
end
end
This is also what the rust version does.
- Jtsummers 5y agoIt does the same on line 22. But I'm not at a computer to see if addressing it there as well will have a comparable performance improvement.
- adgjlsfhk1 5y agoThat one doesn't matter nearly as much (I couldn't detect a performance difference). match_constraints isn't called nearly as frequently.