-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify the types of built-in and custom word lists #16
Conversation
Thank you so much for this work! However, I've become a bit attached to the build script technique, if for nothing else than the speed boost. I had been using the include_str! macro to read-in the word lists, but when I switched to a build script I got an almost 1000x improvement. (See #2) As proof, if I move the
+77584%! (This same benchmark averages about 780 nanoseconds on my same machine.) A more practical benchmarkWe can also use Hyperfine as a more real-word benchmark. On my laptop, Now, certainly, one question here is "Is ~0.3 milliseconds an appreciable difference?" OR more specifically, "Is ~0.3 milliseconds worth a slightly 'messier' This is a long way of saying I want to have my cake and to eat it too. I guess we could try making |
Just tried the approach of "convert built-in lists to pub fn fetch_list(list_choice: ListChoice) -> Vec<String> {
match list_choice {
ListChoice::Long => WL_LONG
.iter()
.map(|w| w.to_string())
.collect::<Vec<String>>(),
ListChoice::Medium => WL_MEDIUM
.iter()
.map(|w| w.to_string())
.collect::<Vec<String>>(),
ListChoice::Qwerty => WL_QWERTY
.iter()
.map(|w| w.to_string())
.collect::<Vec<String>>(),
ListChoice::Alpha => WL_ALPHA
.iter()
.map(|w| w.to_string())
.collect::<Vec<String>>(),
ListChoice::Eff => WL_EFF
.iter()
.map(|w| w.to_string())
.collect::<Vec<String>>(),
ListChoice::Effshort => WL_EFFSHORT
.iter()
.map(|w| w.to_string())
.collect::<Vec<String>>(),
ListChoice::Mnemonicode => WL_MNEMONICODE
.iter()
.map(|w| w.to_string())
.collect::<Vec<String>>(),
}
} The bummer is that this option also slows the benchmark way down.
|
I have completely changed the approach now to remove the duplicated code while keeping your performance as before. When it comes to the way you generate code here, you might like to try writing a macro similar to pub fn fetch_list(list_choice: ListChoice) -> &'static [&'static str] {
match list_choice {
ListChoice::Long => include_lines!("../word-lists/orchard-street-long.txt"),
ListChoice::Medium => include_lines!("../word-lists/orchard-street-medium.txt"),
ListChoice::Qwerty => include_lines!("../word-lists/orchard-street-qwerty.txt"),
ListChoice::Alpha => include_lines!("../word-lists/orchard-street-alpha.txt"),
ListChoice::Eff => include_lines!("../word-lists/eff-long.txt"),
ListChoice::Effshort => include_lines!("../word-lists/eff-short-1.txt"),
ListChoice::Mnemonicode => include_lines!("../word-lists/mnemonicode.txt"),
}
} The performance will be the same, but I think you will find it to be more idiomatic rust to use macros over code generation. |
Oh, of course, someone has already done it, here is a crate for |
Brilliant! Clever! Merged! Thanks again. |
Applies the same technique of
T: AsRef<str>
to fix #15Original:
aThe core change is to make
fetch_list
return aVec<String>
using:This would be possible without some of my more radical change: removing the custom build script in order to bundle the string lists as just strings.