diff --git a/Cargo.toml b/Cargo.toml index 9f3151f..623a83c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,8 @@ path = "src/lib.rs" [dev-dependencies] rand = "0.8" +criterion = "0.5.0" + +[[bench]] +name = "murmurhash3" +harness = false \ No newline at end of file diff --git a/benches/murmurhash3.rs b/benches/murmurhash3.rs new file mode 100644 index 0000000..97bd178 --- /dev/null +++ b/benches/murmurhash3.rs @@ -0,0 +1,48 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +use rand::RngCore; +use std::iter::FromIterator; + +use murmurhash3::{murmurhash3_x64_128, murmurhash3_x86_32}; + +fn run_bench(c: &mut Criterion, size: u64) { + c.bench_function("murmurhash 256k", |b| { + let mut data: Vec = FromIterator::from_iter((0..size).map(|_| 0u8)); + rand::thread_rng().fill_bytes(&mut data); + + b.iter(|| { + black_box(murmurhash3_x86_32(&data, 0)); + }); + }); +} + +fn run_bench128(c: &mut Criterion, size: u64) { + c.bench_function("murmurhash128 256k", |b| { + let mut data: Vec = FromIterator::from_iter((0..size).map(|_| 0u8)); + rand::thread_rng().fill_bytes(&mut data); + + b.iter(|| { + black_box(murmurhash3_x64_128(&data, 0)); + }); + }); +} + +fn bench_random_256k(c: &mut Criterion) { + run_bench(c, 256 * 1024); +} + +fn bench_random_16b(c: &mut Criterion) { + run_bench(c, 16); +} + +fn bench_random128_256k(c: &mut Criterion) { + run_bench128(c, 256 * 1024); +} + +fn bench_random128_16b(c: &mut Criterion) { + run_bench128(c, 16); +} + +criterion_group!(benches, bench_random_16b, bench_random_256k); +criterion_group!(benches128, bench_random128_16b, bench_random128_256k); +criterion_main!(benches); diff --git a/src/mmh3_128.rs b/src/mmh3_128.rs index da01943..01ff8e7 100644 --- a/src/mmh3_128.rs +++ b/src/mmh3_128.rs @@ -202,36 +202,4 @@ mod test { fn test_large_data() { assert_eq!(murmurhash3_x64_128("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam at consequat massa. Cras eleifend pellentesque ex, at dignissim libero maximus ut. Sed eget nulla felis".as_bytes(), 0), (9455322759164802692, 17863277201603478371)); } - - #[cfg(feature = "nightly")] - mod bench { - extern crate rand; - extern crate test; - - use self::rand::Rng; - use self::test::{black_box, Bencher}; - use std::iter::FromIterator; - - use super::super::murmurhash3_x64_128; - - fn run_bench(b: &mut Bencher, size: u64) { - let mut data: Vec = FromIterator::from_iter((0..size).map(|_| 0u8)); - rand::thread_rng().fill_bytes(&mut data); - - b.bytes = size; - b.iter(|| { - black_box(murmurhash3_x64_128(&data, 0)); - }); - } - - #[bench] - fn bench_random_256k(b: &mut Bencher) { - run_bench(b, 256 * 1024); - } - - #[bench] - fn bench_random_16b(b: &mut Bencher) { - run_bench(b, 16); - } - } } diff --git a/src/mmh3_32.rs b/src/mmh3_32.rs index fde962c..d37c07f 100644 --- a/src/mmh3_32.rs +++ b/src/mmh3_32.rs @@ -80,36 +80,4 @@ mod test { fn test_large_data() { assert_eq!(murmurhash3_x86_32("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam at consequat massa. Cras eleifend pellentesque ex, at dignissim libero maximus ut. Sed eget nulla felis".as_bytes(), 0), 1004899618); } - - #[cfg(feature = "nightly")] - mod bench { - extern crate rand; - extern crate test; - - use self::rand::Rng; - use self::test::{black_box, Bencher}; - use std::iter::FromIterator; - - use super::super::murmurhash3_x86_32; - - fn run_bench(b: &mut Bencher, size: u64) { - let mut data: Vec = FromIterator::from_iter((0..size).map(|_| 0u8)); - rand::thread_rng().fill_bytes(&mut data); - - b.bytes = size; - b.iter(|| { - black_box(murmurhash3_x86_32(&data, 0)); - }); - } - - #[bench] - fn bench_random_256k(b: &mut Bencher) { - run_bench(b, 256 * 1024); - } - - #[bench] - fn bench_random_16b(b: &mut Bencher) { - run_bench(b, 16); - } - } }