mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-26 00:47:31 +02:00
Benchmarks for as_bytes/from_bytes, clone, list
Signed-off-by: Erik Hollensbe <git@hollensbe.org>
This commit is contained in:
parent
544420695b
commit
95d28c0fb9
5 changed files with 172 additions and 0 deletions
|
@ -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
|
||||
|
|
19
iblt/benches/clone.rs
Normal file
19
iblt/benches/clone.rs
Normal file
|
@ -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);
|
39
iblt/benches/list.rs
Normal file
39
iblt/benches/list.rs
Normal file
|
@ -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);
|
78
iblt/benches/merge.rs
Normal file
78
iblt/benches/merge.rs
Normal file
|
@ -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);
|
19
iblt/benches/to_from_bytes.rs
Normal file
19
iblt/benches/to_from_bytes.rs
Normal file
|
@ -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);
|
Loading…
Add table
Reference in a new issue