diff --git a/iblt/Cargo.toml b/iblt/Cargo.toml index 16c2d8481..41232812d 100644 --- a/iblt/Cargo.toml +++ b/iblt/Cargo.toml @@ -17,5 +17,22 @@ zerocopy = { version = "0.6.1", features = ["alloc"] } [dev-dependencies] rand = ">=0" +criterion = ">=0" [lib] + +[[bench]] +name = "to_from_bytes" +harness = false + +[[bench]] +name = "clone" +harness = false + +[[bench]] +name = "list" +harness = false + +[[bench]] +name = "merge" +harness = false diff --git a/iblt/benches/clone.rs b/iblt/benches/clone.rs new file mode 100644 index 000000000..0199de2e2 --- /dev/null +++ b/iblt/benches/clone.rs @@ -0,0 +1,19 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use iblt::IBLT; + +const CAPACITY: usize = 4096; +type OurIBLT = IBLT<[u8; 32], CAPACITY, 3>; + +pub fn criterion_benchmark(c: &mut Criterion) { + let mut iblt = OurIBLT::new(); + for _ in 0..CAPACITY { + let mut v = [0u8; 32]; + v.fill_with(rand::random); + iblt.insert(&v); + } + + c.bench_function("clone", |b| b.iter(|| iblt.clone())); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/iblt/benches/list.rs b/iblt/benches/list.rs new file mode 100644 index 000000000..9987ab3df --- /dev/null +++ b/iblt/benches/list.rs @@ -0,0 +1,39 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use iblt::IBLT; + +const CAPACITY: usize = 4096; +type IBLT32 = IBLT<[u8; 32], CAPACITY, 3>; +type IBLT16 = IBLT<[u8; 16], CAPACITY, 3>; +type IBLT8 = IBLT<[u8; 8], CAPACITY, 3>; + +pub fn criterion_benchmark(c: &mut Criterion) { + let mut iblt = IBLT32::new(); + for _ in 0..CAPACITY { + let mut v = [0u8; 32]; + v.fill_with(rand::random); + iblt.insert(&v); + } + + c.bench_function("list 32", |b| b.iter(|| iblt.list(|_, _| {}))); + + let mut iblt = IBLT16::new(); + for _ in 0..CAPACITY { + let mut v = [0u8; 16]; + v.fill_with(rand::random); + iblt.insert(&v); + } + + c.bench_function("list 16", |b| b.iter(|| iblt.list(|_, _| {}))); + + let mut iblt = IBLT8::new(); + for _ in 0..CAPACITY { + let mut v = [0u8; 8]; + v.fill_with(rand::random); + iblt.insert(&v); + } + + c.bench_function("list 8", |b| b.iter(|| iblt.list(|_, _| {}))); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/iblt/benches/merge.rs b/iblt/benches/merge.rs new file mode 100644 index 000000000..05d994562 --- /dev/null +++ b/iblt/benches/merge.rs @@ -0,0 +1,78 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use iblt::IBLT; + +const CAPACITY: usize = 4096; +type IBLT32 = IBLT<[u8; 32], CAPACITY, 3>; +type IBLT16 = IBLT<[u8; 16], CAPACITY, 3>; +type IBLT8 = IBLT<[u8; 8], CAPACITY, 3>; + +pub fn criterion_benchmark(c: &mut Criterion) { + let mut orig = IBLT32::new(); + let mut new = IBLT32::new(); + for _ in 0..CAPACITY { + let mut v = [0u8; 32]; + v.fill_with(rand::random); + orig.insert(&v); + } + + for _ in 0..CAPACITY { + let mut v = [0u8; 32]; + v.fill_with(rand::random); + new.insert(&v); + } + + c.bench_function("merge 32", |b| { + b.iter(|| { + let mut new2 = new.clone(); + orig.subtract(&new); + new2.subtract(&orig); + }) + }); + + let mut orig = IBLT16::new(); + let mut new = IBLT16::new(); + for _ in 0..CAPACITY { + let mut v = [0u8; 16]; + v.fill_with(rand::random); + orig.insert(&v); + } + + for _ in 0..CAPACITY { + let mut v = [0u8; 16]; + v.fill_with(rand::random); + new.insert(&v); + } + + c.bench_function("merge 16", |b| { + b.iter(|| { + let mut new2 = new.clone(); + orig.subtract(&new); + new2.subtract(&orig); + }) + }); + + let mut orig = IBLT8::new(); + let mut new = IBLT8::new(); + for _ in 0..CAPACITY { + let mut v = [0u8; 8]; + v.fill_with(rand::random); + orig.insert(&v); + } + + for _ in 0..CAPACITY { + let mut v = [0u8; 8]; + v.fill_with(rand::random); + new.insert(&v); + } + + c.bench_function("merge 8", |b| { + b.iter(|| { + let mut new2 = new.clone(); + orig.subtract(&new); + new2.subtract(&orig); + }) + }); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/iblt/benches/to_from_bytes.rs b/iblt/benches/to_from_bytes.rs new file mode 100644 index 000000000..ede76d504 --- /dev/null +++ b/iblt/benches/to_from_bytes.rs @@ -0,0 +1,19 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use iblt::IBLT; + +const CAPACITY: usize = 4096; +type OurIBLT = IBLT<[u8; 32], CAPACITY, 3>; + +pub fn criterion_benchmark(c: &mut Criterion) { + let mut iblt = OurIBLT::new(); + for _ in 0..CAPACITY { + let mut v = [0u8; 32]; + v.fill_with(rand::random); + iblt.insert(&v); + } + + c.bench_function("to_from_bytes", |b| b.iter(|| OurIBLT::from_bytes(iblt.as_bytes()))); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches);