mirror of
https://gitee.com/openharmony/third_party_rust_strsim-rs
synced 2024-11-26 17:31:18 +00:00
Add some simple benchmarks.
This commit is contained in:
parent
ce93ac1652
commit
e178e6995f
@ -50,6 +50,8 @@ fn main() {
|
||||
If you don't want to install Rust itself, you can run `$ ./dev` for a
|
||||
development CLI if you have [Docker] installed.
|
||||
|
||||
Benchmarks require a Nightly toolchain. They are run by `cargo +nightly bench`.
|
||||
|
||||
### License
|
||||
[MIT](https://github.com/dguo/strsim-rs/blob/master/LICENSE)
|
||||
|
||||
|
66
benches/benches.rs
Normal file
66
benches/benches.rs
Normal file
@ -0,0 +1,66 @@
|
||||
//! Benchmarks for strsim.
|
||||
|
||||
#![feature(test)]
|
||||
|
||||
extern crate strsim;
|
||||
|
||||
mod benches {
|
||||
use super::*;
|
||||
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[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_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_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);
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user