sort unstably

flake-overlay-tweak
Brian Hicks 2021-08-24 17:00:28 -05:00
parent b3914c1e6b
commit 3e4dc4167c
2 changed files with 16 additions and 1 deletions

View File

@ -100,3 +100,18 @@ Benchmark #1: ./target/release/similar-sort benchmark < /usr/share/dict/words
```
... well, no. Probably not a good idea.
## Unstable Sort
Looking at the Go implementation again, it looks like I used an unstable sort instead of a stable one.
OK, that's fine, we'll grab that speedup:
```
hyperfine './target/release/similar-sort benchmark < /usr/share/dict/words'
Benchmark #1: ./target/release/similar-sort benchmark < /usr/share/dict/words
Time (mean ± σ): 502.2 ms ± 6.6 ms [User: 660.1 ms, System: 12.7 ms]
Range (min … max): 491.5 ms … 513.2 ms 10 runs
```
And quite a speedup it is!
About 150ms over the previous improvement.

View File

@ -31,7 +31,7 @@ fn try_main() -> Result<()> {
.collect::<io::Result<Vec<String>>>()
.context("could not read lines from stdin")?;
lines.par_sort_by_key(|candidate| levenshtein(&opts.target, candidate));
lines.par_sort_unstable_by_key(|candidate| levenshtein(&opts.target, candidate));
let mut out = BufWriter::new(stdout());
for candidate in lines {