Skip to content

Commit

Permalink
use a bump allocator again
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Aug 24, 2021
1 parent 3377430 commit 35907da
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
21 changes: 21 additions & 0 deletions BENCHMARKING.md
Expand Up @@ -170,3 +170,24 @@ Summary
```

Yep!

## Bump Allocation (again)

Let's try the bump allocator again... it seemed like a fluke that it produced such a severe performance degradation.

```
$ hyperfine './result/bin/similar-sort define < /usr/share/dict/words' './target/release/similar-sort benchmark < /usr/share/dict/words'
Benchmark #1: ./result/bin/similar-sort define < /usr/share/dict/words
Time (mean ± σ): 286.2 ms ± 5.0 ms [User: 251.4 ms, System: 72.5 ms]
Range (min … max): 280.8 ms … 298.4 ms 10 runs
Benchmark #2: ./target/release/similar-sort benchmark < /usr/share/dict/words
Time (mean ± σ): 111.3 ms ± 3.4 ms [User: 94.7 ms, System: 16.0 ms]
Range (min … max): 104.1 ms … 118.5 ms 24 runs
Summary
'./target/release/similar-sort benchmark < /usr/share/dict/words' ran
2.57 ± 0.09 times faster than './result/bin/similar-sort define < /usr/share/dict/words'
```

That seems more like what I'd expect!
38 changes: 36 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -7,7 +7,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
structopt = "0.3.22"
bump_alloc = "0.1.0"
color-eyre = "0.5.7"
rayon = "1.5.1"
strsim = "0.10.0"
structopt = "0.3.22"
4 changes: 4 additions & 0 deletions src/main.rs
Expand Up @@ -4,6 +4,9 @@ use std::io::{self, stdin, stdout, BufRead, BufWriter, Write};
use strsim::levenshtein;
use structopt::StructOpt;

#[global_allocator]
static A: bump_alloc::BumpAlloc = bump_alloc::BumpAlloc::new();

// works like `sort`, but sorts according to Levenshtein distance instead of
// alphanumerically.
#[derive(StructOpt)]
Expand Down Expand Up @@ -42,6 +45,7 @@ fn try_main() -> Result<()> {
for (_, candidate) in distances {
writeln!(out, "{}", candidate).context("could not write to stdout")?;
}
out.flush().context("could not finish writing to stdout")?;

Ok(())
}

0 comments on commit 35907da

Please sign in to comment.