Skip to content

Commit

Permalink
add first benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Oct 20, 2023
1 parent 45b712d commit d585e22
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ default = ["fzf-v1"]
fzf-v1 = []

# Private features.
bench = ["tests"]
tests = ["fzf-v1"]

[dependencies]

[dev-dependencies]
criterion = "0.5"

[[test]]
name = "fzf-v1"
path = "./tests/fzf_v1.rs"
name = "fzf_v1"
required-features = ["tests"]

[[bench]]
name = "fzf_v1"
harness = false
required-features = ["bench"]
39 changes: 39 additions & 0 deletions benches/fzf_v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use criterion::{
criterion_group,
criterion_main,
measurement::WallTime,
Bencher,
BenchmarkGroup,
Criterion,
};
use norm::{
fzf::{FzfQuery, FzfV1},
CaseSensitivity,
Metric,
};

fn short(fzf: &FzfV1, b: &mut Bencher) {
let jelly = FzfQuery::new("jelly");
b.iter(|| fzf.distance(jelly, "jellyfish"))
}

fn sensitive_with_ranges() -> FzfV1 {
FzfV1::new()
.with_case_sensitivity(CaseSensitivity::Sensitive)
.with_matched_ranges(true)
}

fn short_case_sensitive_with_ranges(c: &mut Criterion) {
let fzf = sensitive_with_ranges();

group(c).bench_function("short_case_sensitive_with_ranges", |b| {
short(&fzf, b)
});
}

fn group(c: &mut Criterion) -> BenchmarkGroup<WallTime> {
c.benchmark_group("fzf_v1")
}

criterion_group!(benches, short_case_sensitive_with_ranges);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion src/algos/fzf_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Distance = u32;
type Score = Distance;

/// TODO: docs.
#[derive(Debug)]
#[derive(Clone, Copy, Debug)]
pub struct FzfQuery<'a> {
/// TODO: docs.
raw: &'a str,
Expand Down

0 comments on commit d585e22

Please sign in to comment.