1 //! Benchmarks for strsim. 2 3 #![feature(test)] 4 5 extern crate strsim; 6 7 mod benches { 8 use self::test::Bencher; 9 use super::*; 10 11 extern crate test; 12 13 #[bench] bench_hamming(bencher: &mut Bencher)14 fn bench_hamming(bencher: &mut Bencher) { 15 let a = "ACAAGATGCCATTGTCCCCCGGCCTCCTGCTGCTGCTGCTCTCCGGGG"; 16 let b = "CCTGGAGGGTGGCCCCACCGGCCGAGACAGCGAGCATATGCAGGAAGC"; 17 bencher.iter(|| { 18 strsim::hamming(a, b).unwrap(); 19 }) 20 } 21 22 #[bench] bench_jaro(bencher: &mut Bencher)23 fn bench_jaro(bencher: &mut Bencher) { 24 let a = "Philosopher Friedrich Nietzsche"; 25 let b = "Philosopher Jean-Paul Sartre"; 26 bencher.iter(|| { 27 strsim::jaro(&a, &b); 28 }) 29 } 30 31 #[bench] bench_jaro_winkler(bencher: &mut Bencher)32 fn bench_jaro_winkler(bencher: &mut Bencher) { 33 let a = "Philosopher Friedrich Nietzsche"; 34 let b = "Philosopher Jean-Paul Sartre"; 35 bencher.iter(|| { 36 strsim::jaro_winkler(&a, &b); 37 }) 38 } 39 40 #[bench] bench_levenshtein(bencher: &mut Bencher)41 fn bench_levenshtein(bencher: &mut Bencher) { 42 let a = "Philosopher Friedrich Nietzsche"; 43 let b = "Philosopher Jean-Paul Sartre"; 44 bencher.iter(|| { 45 strsim::levenshtein(&a, &b); 46 }) 47 } 48 49 #[bench] bench_levenshtein_on_u8(bencher: &mut Bencher)50 fn bench_levenshtein_on_u8(bencher: &mut Bencher) { 51 bencher.iter(|| { 52 strsim::generic_levenshtein(&vec![0u8; 30], &vec![7u8; 31]); 53 }) 54 } 55 56 #[bench] bench_normalized_levenshtein(bencher: &mut Bencher)57 fn bench_normalized_levenshtein(bencher: &mut Bencher) { 58 let a = "Philosopher Friedrich Nietzsche"; 59 let b = "Philosopher Jean-Paul Sartre"; 60 bencher.iter(|| { 61 strsim::normalized_levenshtein(&a, &b); 62 }) 63 } 64 65 #[bench] bench_osa_distance(bencher: &mut Bencher)66 fn bench_osa_distance(bencher: &mut Bencher) { 67 let a = "Philosopher Friedrich Nietzsche"; 68 let b = "Philosopher Jean-Paul Sartre"; 69 bencher.iter(|| { 70 strsim::osa_distance(&a, &b); 71 }) 72 } 73 74 #[bench] bench_damerau_levenshtein(bencher: &mut Bencher)75 fn bench_damerau_levenshtein(bencher: &mut Bencher) { 76 let a = "Philosopher Friedrich Nietzsche"; 77 let b = "Philosopher Jean-Paul Sartre"; 78 bencher.iter(|| { 79 strsim::damerau_levenshtein(&a, &b); 80 }) 81 } 82 83 #[bench] bench_normalized_damerau_levenshtein(bencher: &mut Bencher)84 fn bench_normalized_damerau_levenshtein(bencher: &mut Bencher) { 85 let a = "Philosopher Friedrich Nietzsche"; 86 let b = "Philosopher Jean-Paul Sartre"; 87 bencher.iter(|| { 88 strsim::normalized_damerau_levenshtein(&a, &b); 89 }) 90 } 91 92 #[bench] bench_sorensen_dice(bencher: &mut Bencher)93 fn bench_sorensen_dice(bencher: &mut Bencher) { 94 let a = "Philosopher Friedrich Nietzsche"; 95 let b = "Philosopher Jean-Paul Sartre"; 96 bencher.iter(|| { 97 strsim::sorensen_dice(&a, &b); 98 }) 99 } 100 } 101