From 9c2bd49831e4436ce59764fd1a9d3243b3d76622 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Thu, 4 Jan 2024 20:25:21 +0100 Subject: [PATCH 1/2] remove superfluous module around benchmarks --- benches/benches.rs | 163 ++++++++++++++++++++++----------------------- 1 file changed, 79 insertions(+), 84 deletions(-) diff --git a/benches/benches.rs b/benches/benches.rs index b7ba829..36d892a 100644 --- a/benches/benches.rs +++ b/benches/benches.rs @@ -3,98 +3,93 @@ #![feature(test)] extern crate strsim; +extern crate test; +use self::test::Bencher; -mod benches { - use self::test::Bencher; - use super::*; - - extern crate test; - - #[bench] - fn bench_hamming(bencher: &mut Bencher) { - let a = "ACAAGATGCCATTGTCCCCCGGCCTCCTGCTGCTGCTGCTCTCCGGGG"; - let b = "CCTGGAGGGTGGCCCCACCGGCCGAGACAGCGAGCATATGCAGGAAGC"; - bencher.iter(|| { - strsim::hamming(a, b).unwrap(); - }) - } +#[bench] +fn bench_hamming(bencher: &mut Bencher) { + let a = "ACAAGATGCCATTGTCCCCCGGCCTCCTGCTGCTGCTGCTCTCCGGGG"; + let b = "CCTGGAGGGTGGCCCCACCGGCCGAGACAGCGAGCATATGCAGGAAGC"; + bencher.iter(|| { + strsim::hamming(a, b).unwrap(); + }) +} - #[bench] - fn bench_jaro(bencher: &mut Bencher) { - let a = "Philosopher Friedrich Nietzsche"; - let b = "Philosopher Jean-Paul Sartre"; - bencher.iter(|| { - strsim::jaro(&a, &b); - }) - } +#[bench] +fn bench_jaro(bencher: &mut Bencher) { + let a = "Philosopher Friedrich Nietzsche"; + let b = "Philosopher Jean-Paul Sartre"; + bencher.iter(|| { + strsim::jaro(&a, &b); + }) +} - #[bench] - fn bench_jaro_winkler(bencher: &mut Bencher) { - let a = "Philosopher Friedrich Nietzsche"; - let b = "Philosopher Jean-Paul Sartre"; - bencher.iter(|| { - strsim::jaro_winkler(&a, &b); - }) - } +#[bench] +fn bench_jaro_winkler(bencher: &mut Bencher) { + let a = "Philosopher Friedrich Nietzsche"; + let b = "Philosopher Jean-Paul Sartre"; + bencher.iter(|| { + strsim::jaro_winkler(&a, &b); + }) +} - #[bench] - fn bench_levenshtein(bencher: &mut Bencher) { - let a = "Philosopher Friedrich Nietzsche"; - let b = "Philosopher Jean-Paul Sartre"; - bencher.iter(|| { - strsim::levenshtein(&a, &b); - }) - } +#[bench] +fn bench_levenshtein(bencher: &mut Bencher) { + let a = "Philosopher Friedrich Nietzsche"; + let b = "Philosopher Jean-Paul Sartre"; + bencher.iter(|| { + strsim::levenshtein(&a, &b); + }) +} - #[bench] - fn bench_levenshtein_on_u8(bencher: &mut Bencher) { - bencher.iter(|| { - strsim::generic_levenshtein(&vec![0u8; 30], &vec![7u8; 31]); - }) - } +#[bench] +fn bench_levenshtein_on_u8(bencher: &mut Bencher) { + bencher.iter(|| { + strsim::generic_levenshtein(&vec![0u8; 30], &vec![7u8; 31]); + }) +} - #[bench] - fn bench_normalized_levenshtein(bencher: &mut Bencher) { - let a = "Philosopher Friedrich Nietzsche"; - let b = "Philosopher Jean-Paul Sartre"; - bencher.iter(|| { - strsim::normalized_levenshtein(&a, &b); - }) - } +#[bench] +fn bench_normalized_levenshtein(bencher: &mut Bencher) { + let a = "Philosopher Friedrich Nietzsche"; + let b = "Philosopher Jean-Paul Sartre"; + bencher.iter(|| { + strsim::normalized_levenshtein(&a, &b); + }) +} - #[bench] - fn bench_osa_distance(bencher: &mut Bencher) { - let a = "Philosopher Friedrich Nietzsche"; - let b = "Philosopher Jean-Paul Sartre"; - bencher.iter(|| { - strsim::osa_distance(&a, &b); - }) - } +#[bench] +fn bench_osa_distance(bencher: &mut Bencher) { + let a = "Philosopher Friedrich Nietzsche"; + let b = "Philosopher Jean-Paul Sartre"; + bencher.iter(|| { + strsim::osa_distance(&a, &b); + }) +} - #[bench] - fn bench_damerau_levenshtein(bencher: &mut Bencher) { - let a = "Philosopher Friedrich Nietzsche"; - let b = "Philosopher Jean-Paul Sartre"; - bencher.iter(|| { - strsim::damerau_levenshtein(&a, &b); - }) - } +#[bench] +fn bench_damerau_levenshtein(bencher: &mut Bencher) { + let a = "Philosopher Friedrich Nietzsche"; + let b = "Philosopher Jean-Paul Sartre"; + bencher.iter(|| { + strsim::damerau_levenshtein(&a, &b); + }) +} - #[bench] - fn bench_normalized_damerau_levenshtein(bencher: &mut Bencher) { - let a = "Philosopher Friedrich Nietzsche"; - let b = "Philosopher Jean-Paul Sartre"; - bencher.iter(|| { - strsim::normalized_damerau_levenshtein(&a, &b); - }) - } +#[bench] +fn bench_normalized_damerau_levenshtein(bencher: &mut Bencher) { + let a = "Philosopher Friedrich Nietzsche"; + let b = "Philosopher Jean-Paul Sartre"; + bencher.iter(|| { + strsim::normalized_damerau_levenshtein(&a, &b); + }) +} - #[bench] - fn bench_sorensen_dice(bencher: &mut Bencher) { - let a = "Philosopher Friedrich Nietzsche"; - let b = "Philosopher Jean-Paul Sartre"; - bencher.iter(|| { - strsim::sorensen_dice(&a, &b); - }) - } +#[bench] +fn bench_sorensen_dice(bencher: &mut Bencher) { + let a = "Philosopher Friedrich Nietzsche"; + let b = "Philosopher Jean-Paul Sartre"; + bencher.iter(|| { + strsim::sorensen_dice(&a, &b); + }) } From 38cb19521a1d3d28c999958feaac1ee2aed7ee28 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Fri, 5 Jan 2024 08:23:57 +0100 Subject: [PATCH 2/2] cleanup unnecessary references --- benches/benches.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/benches/benches.rs b/benches/benches.rs index 36d892a..15c7041 100644 --- a/benches/benches.rs +++ b/benches/benches.rs @@ -20,7 +20,7 @@ fn bench_jaro(bencher: &mut Bencher) { let a = "Philosopher Friedrich Nietzsche"; let b = "Philosopher Jean-Paul Sartre"; bencher.iter(|| { - strsim::jaro(&a, &b); + strsim::jaro(a, b); }) } @@ -29,7 +29,7 @@ fn bench_jaro_winkler(bencher: &mut Bencher) { let a = "Philosopher Friedrich Nietzsche"; let b = "Philosopher Jean-Paul Sartre"; bencher.iter(|| { - strsim::jaro_winkler(&a, &b); + strsim::jaro_winkler(a, b); }) } @@ -38,7 +38,7 @@ fn bench_levenshtein(bencher: &mut Bencher) { let a = "Philosopher Friedrich Nietzsche"; let b = "Philosopher Jean-Paul Sartre"; bencher.iter(|| { - strsim::levenshtein(&a, &b); + strsim::levenshtein(a, b); }) } @@ -54,7 +54,7 @@ fn bench_normalized_levenshtein(bencher: &mut Bencher) { let a = "Philosopher Friedrich Nietzsche"; let b = "Philosopher Jean-Paul Sartre"; bencher.iter(|| { - strsim::normalized_levenshtein(&a, &b); + strsim::normalized_levenshtein(a, b); }) } @@ -63,7 +63,7 @@ fn bench_osa_distance(bencher: &mut Bencher) { let a = "Philosopher Friedrich Nietzsche"; let b = "Philosopher Jean-Paul Sartre"; bencher.iter(|| { - strsim::osa_distance(&a, &b); + strsim::osa_distance(a, b); }) } @@ -72,7 +72,7 @@ fn bench_damerau_levenshtein(bencher: &mut Bencher) { let a = "Philosopher Friedrich Nietzsche"; let b = "Philosopher Jean-Paul Sartre"; bencher.iter(|| { - strsim::damerau_levenshtein(&a, &b); + strsim::damerau_levenshtein(a, b); }) } @@ -81,7 +81,7 @@ fn bench_normalized_damerau_levenshtein(bencher: &mut Bencher) { let a = "Philosopher Friedrich Nietzsche"; let b = "Philosopher Jean-Paul Sartre"; bencher.iter(|| { - strsim::normalized_damerau_levenshtein(&a, &b); + strsim::normalized_damerau_levenshtein(a, b); }) } @@ -90,6 +90,6 @@ fn bench_sorensen_dice(bencher: &mut Bencher) { let a = "Philosopher Friedrich Nietzsche"; let b = "Philosopher Jean-Paul Sartre"; bencher.iter(|| { - strsim::sorensen_dice(&a, &b); + strsim::sorensen_dice(a, b); }) }