Skip to content

Commit

Permalink
adjust benchmarks and fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Dec 1, 2023
1 parent b094335 commit dc5f04f
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 86 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changelog
---------

[0.4.0] - 2023-12-01
^^^^^^^^^^^^^^^^^^^^
Changed
~~~~~~~
* rewrite of function signatures to reduce boilerplate
* return type now automatically deduced, so no more unwrapping needed
when ``score_cutoff`` is not used
* optional arguments now in Arg structs uisng the builder pattern to reduce amount
of extra arguments
* extra overload ``*_with_args`` for a variant with args, while the default version accepts
only two sequences

The signatures is expected to largely stay this way for the foreseeable future.

[0.3.2] - 2023-11-29
^^^^^^^^^^^^^^^^^^^^
Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
description="rapid fuzzy string matching library"
name = "rapidfuzz"
version = "0.3.2"
version = "0.4.0"
authors = ["maxbachmann <[email protected]>"]
edition = "2021"
readme = "Readme.md"
Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/damerau_levenshtein.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ pub struct Texts {
}

fn fuzz(texts: Texts) {
damerau_levenshtein::distance(texts.s1.chars(), texts.s2.chars(), None, None)
.expect("does not return None");
damerau_levenshtein::distance(texts.s1.chars(), texts.s2.chars());

damerau_levenshtein::BatchComparator::new(texts.s1.chars())
.distance(texts.s2.chars(), None, None)
.expect("does not return None");
damerau_levenshtein::BatchComparator::new(texts.s1.chars()).distance(texts.s2.chars());
}

fuzz_target!(|texts: Texts| {
Expand Down
6 changes: 2 additions & 4 deletions fuzz/fuzz_targets/indel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ pub struct Texts {
}

fn fuzz(texts: Texts) {
indel::distance(texts.s1.chars(), texts.s2.chars(), None, None).expect("does not return None");
indel::distance(texts.s1.chars(), texts.s2.chars());

indel::BatchComparator::new(texts.s1.chars())
.distance(texts.s2.chars(), None, None)
.expect("does not return None");
indel::BatchComparator::new(texts.s1.chars()).distance(texts.s2.chars());
}

fuzz_target!(|texts: Texts| {
Expand Down
6 changes: 2 additions & 4 deletions fuzz/fuzz_targets/jaro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ pub struct Texts {
}

fn fuzz(texts: Texts) {
jaro::distance(texts.s1.chars(), texts.s2.chars(), None, None).expect("does not return None");
jaro::distance(texts.s1.chars(), texts.s2.chars());

jaro::BatchComparator::new(texts.s1.chars())
.distance(texts.s2.chars(), None, None)
.expect("does not return None");
jaro::BatchComparator::new(texts.s1.chars()).distance(texts.s2.chars());
}

fuzz_target!(|texts: Texts| {
Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/jaro_winkler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ pub struct Texts {
}

fn fuzz(texts: Texts) {
jaro_winkler::distance(texts.s1.chars(), texts.s2.chars(), None, None, None)
.expect("does not return None");
jaro_winkler::distance(texts.s1.chars(), texts.s2.chars());

jaro_winkler::BatchComparator::new(texts.s1.chars(), None)
.distance(texts.s2.chars(), None, None)
.expect("does not return None");
jaro_winkler::BatchComparator::new(texts.s1.chars()).distance(texts.s2.chars());
}

fuzz_target!(|texts: Texts| {
Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/lcs_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ pub struct Texts {
}

fn fuzz(texts: Texts) {
lcs_seq::distance(texts.s1.chars(), texts.s2.chars(), None, None)
.expect("does not return None");
lcs_seq::distance(texts.s1.chars(), texts.s2.chars());

lcs_seq::BatchComparator::new(texts.s1.chars())
.distance(texts.s2.chars(), None, None)
.expect("does not return None");
lcs_seq::BatchComparator::new(texts.s1.chars()).distance(texts.s2.chars());
}

fuzz_target!(|texts: Texts| {
Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/levenshtein.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ pub struct Texts {
}

fn fuzz(texts: Texts) {
levenshtein::distance(texts.s1.chars(), texts.s2.chars(), None, None, None)
.expect("does not return None");
levenshtein::distance(texts.s1.chars(), texts.s2.chars());

levenshtein::BatchComparator::new(texts.s1.chars(), None)
.distance(texts.s2.chars(), None, None)
.expect("does not return None");
levenshtein::BatchComparator::new(texts.s1.chars()).distance(texts.s2.chars());
}

fuzz_target!(|texts: Texts| {
Expand Down
2 changes: 0 additions & 2 deletions rapidfuzz-benches/benches/bench_damerau_levenshtein.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fn benchmark(c: &mut Criterion) {
black_box(distance::damerau_levenshtein::distance(
val.0.bytes(),
val.1.bytes(),
None,
None,
));
})
});
Expand Down
16 changes: 8 additions & 8 deletions rapidfuzz-benches/benches/bench_generic_levenshtein.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ fn benchmark(c: &mut Criterion) {
for i in lens {
let s1 = generate(i);
let s2 = generate(i);
let args =
distance::levenshtein::Args::default().weights(&distance::levenshtein::WeightTable {
insertion_cost: 1,
deletion_cost: 2,
substitution_cost: 3,
});

group.bench_with_input(BenchmarkId::new("rapidfuzz", i), &(&s1, &s2), |b, val| {
b.iter(|| {
black_box(distance::levenshtein::distance(
black_box(distance::levenshtein::distance_with_args(
val.0.bytes(),
val.1.bytes(),
Some(distance::levenshtein::WeightTable {
insertion_cost: 1,
deletion_cost: 2,
substitution_cost: 3,
}),
None,
None,
&args,
));
})
});
Expand Down
9 changes: 2 additions & 7 deletions rapidfuzz-benches/benches/bench_indel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ fn benchmark(c: &mut Criterion) {

group.bench_with_input(BenchmarkId::new("rapidfuzz", i), &(&s1, &s2), |b, val| {
b.iter(|| {
black_box(distance::indel::distance(
val.0.bytes(),
val.1.bytes(),
None,
None,
));
black_box(distance::indel::distance(val.0.bytes(), val.1.bytes()));
})
});

Expand All @@ -48,7 +43,7 @@ fn benchmark(c: &mut Criterion) {
&(&cached, &s2),
|b, val| {
b.iter(|| {
black_box(cached.distance(val.1.bytes(), None, None));
black_box(cached.distance(val.1.bytes()));
})
},
);
Expand Down
9 changes: 2 additions & 7 deletions rapidfuzz-benches/benches/bench_jaro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ fn benchmark(c: &mut Criterion) {

group.bench_with_input(BenchmarkId::new("rapidfuzz", i), &(&s1, &s2), |b, val| {
b.iter(|| {
black_box(distance::jaro::similarity(
val.0.bytes(),
val.1.bytes(),
None,
None,
));
black_box(distance::jaro::similarity(val.0.bytes(), val.1.bytes()));
})
});

Expand All @@ -48,7 +43,7 @@ fn benchmark(c: &mut Criterion) {
&(&cached, &s2),
|b, val| {
b.iter(|| {
black_box(cached.similarity(val.1.bytes(), None, None));
black_box(cached.similarity(val.1.bytes()));
})
},
);
Expand Down
7 changes: 2 additions & 5 deletions rapidfuzz-benches/benches/bench_jaro_winkler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,17 @@ fn benchmark(c: &mut Criterion) {
black_box(distance::jaro_winkler::similarity(
val.0.bytes(),
val.1.bytes(),
None,
None,
None,
));
})
});

let cached = distance::jaro_winkler::BatchComparator::new(s1.bytes(), None);
let cached = distance::jaro_winkler::BatchComparator::new(s1.bytes());
group.bench_with_input(
BenchmarkId::new("rapidfuzz (BatchComparator)", i),
&(&cached, &s2),
|b, val| {
b.iter(|| {
black_box(cached.similarity(val.1.bytes(), None, None));
black_box(cached.similarity(val.1.bytes()));
})
},
);
Expand Down
9 changes: 2 additions & 7 deletions rapidfuzz-benches/benches/bench_lcs_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ fn benchmark(c: &mut Criterion) {

group.bench_with_input(BenchmarkId::new("rapidfuzz", i), &(&s1, &s2), |b, val| {
b.iter(|| {
black_box(distance::lcs_seq::similarity(
val.0.bytes(),
val.1.bytes(),
None,
None,
));
black_box(distance::lcs_seq::similarity(val.0.bytes(), val.1.bytes()));
})
});

Expand All @@ -48,7 +43,7 @@ fn benchmark(c: &mut Criterion) {
&(&cached, &s2),
|b, val| {
b.iter(|| {
black_box(cached.similarity(val.1.bytes(), None, None));
black_box(cached.similarity(val.1.bytes()));
})
},
);
Expand Down
16 changes: 2 additions & 14 deletions rapidfuzz-benches/benches/bench_levenshtein.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ impl<'a, 'b> IntoIterator for &'a StringWrapper<'b> {
fn benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Levenshtein");

assert_eq!(
5,
levenshtein::distance(
"kitten".chars(),
"sitting".chars(),
&levenshtein::Args::default().weights(weights)
)
);

for i in (2..128).step_by(2) {
let s1 = generate(i);
let s2 = generate(i);
Expand All @@ -45,9 +36,6 @@ fn benchmark(c: &mut Criterion) {
black_box(distance::levenshtein::distance(
val.0.bytes(),
val.1.bytes(),
None,
None,
None,
));
})
});
Expand All @@ -60,13 +48,13 @@ fn benchmark(c: &mut Criterion) {
})
});

let cached = distance::levenshtein::BatchComparator::new(s1.bytes(), None);
let cached = distance::levenshtein::BatchComparator::new(s1.bytes());
group.bench_with_input(
BenchmarkId::new("rapidfuzz (BatchComparator)", i),
&(&cached, &s2),
|b, val| {
b.iter(|| {
black_box(cached.distance(val.1.bytes(), None, None));
black_box(cached.distance(val.1.bytes()));
})
},
);
Expand Down
9 changes: 2 additions & 7 deletions rapidfuzz-benches/benches/bench_osa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ fn benchmark(c: &mut Criterion) {

group.bench_with_input(BenchmarkId::new("rapidfuzz", i), &(&s1, &s2), |b, val| {
b.iter(|| {
black_box(distance::osa::distance(
val.0.chars(),
val.1.chars(),
None,
None,
));
black_box(distance::osa::distance(val.0.chars(), val.1.chars()));
})
});

Expand All @@ -48,7 +43,7 @@ fn benchmark(c: &mut Criterion) {
&(&cached, &s2),
|b, val| {
b.iter(|| {
black_box(cached.distance(val.1.chars(), None, None));
black_box(cached.distance(val.1.chars()));
})
},
);
Expand Down

0 comments on commit dc5f04f

Please sign in to comment.