Update.
This commit is contained in:
@@ -11,7 +11,7 @@ use rand::{Rng, SeedableRng, XorShiftRng};
|
||||
|
||||
use bit_set::BitSet;
|
||||
|
||||
fn default_set<C: FromIterator<u64>>(n: usize) -> C {
|
||||
fn random<C: FromIterator<u64>>(n: usize) -> C {
|
||||
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
|
||||
|
||||
(0..n).map(|_| rng.next_u64()).collect()
|
||||
@@ -33,20 +33,77 @@ fn insert(data: &[u64]) {
|
||||
}
|
||||
}
|
||||
|
||||
fn sub(a: &BitSet, b: &BitSet) {
|
||||
fn iter(set: &BitSet) {
|
||||
set.iter().collect::<Vec<_>>();
|
||||
}
|
||||
|
||||
fn is_subset(a: &BitSet, b: &BitSet) {
|
||||
a.is_subset(b);
|
||||
}
|
||||
|
||||
fn ops_bit_or(a: &BitSet, b: &BitSet) {
|
||||
a | b;
|
||||
}
|
||||
|
||||
fn ops_sub(a: &BitSet, b: &BitSet) {
|
||||
a - b;
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let data: Vec<_> = default_set(1000);
|
||||
// c.sample_size(200);
|
||||
|
||||
c.bench_function("contains", |b| b.iter(|| contains(&data)));
|
||||
c.bench_function("insert", |b| b.iter(|| insert(&data)));
|
||||
c.bench_function("contains", move |b| {
|
||||
let data: Vec<_> = random(10_000);
|
||||
|
||||
let lhs: BitSet = default_set(1000);
|
||||
let rhs: BitSet = default_set(1000);
|
||||
b.iter(|| contains(&data));
|
||||
});
|
||||
|
||||
c.bench_function("sub", |b| b.iter(|| sub(&lhs, &rhs)));
|
||||
c.bench_function("insert", move |b| {
|
||||
let data: Vec<_> = random(10_000);
|
||||
|
||||
b.iter(|| insert(&data));
|
||||
});
|
||||
|
||||
c.bench_function("iter", move |b| {
|
||||
let set: BitSet = random(10_000);
|
||||
|
||||
b.iter(|| iter(&set));
|
||||
});
|
||||
|
||||
c.bench_function("is_subset (>)", |b| {
|
||||
let lhs: BitSet = random(10_000);
|
||||
let rhs: BitSet = random(5_000);
|
||||
|
||||
b.iter(|| is_subset(&lhs, &rhs));
|
||||
});
|
||||
|
||||
c.bench_function("is_subset (<)", |b| {
|
||||
let lhs: BitSet = random(5_000);
|
||||
let rhs: BitSet = random(10_000);
|
||||
|
||||
b.iter(|| is_subset(&lhs, &rhs));
|
||||
});
|
||||
|
||||
c.bench_function("is_subset (=)", |b| {
|
||||
let lhs: BitSet = random(10_000);
|
||||
let rhs: BitSet = random(10_000);
|
||||
|
||||
b.iter(|| is_subset(&lhs, &rhs));
|
||||
});
|
||||
|
||||
c.bench_function("ops_bit_or", move |b| {
|
||||
let lhs: BitSet = random(10_000);
|
||||
let rhs: BitSet = random(10_000);
|
||||
|
||||
b.iter(|| ops_bit_or(&lhs, &rhs));
|
||||
});
|
||||
|
||||
c.bench_function("ops_sub", move |b| {
|
||||
let lhs: BitSet = random(10_000);
|
||||
let rhs: BitSet = random(10_000);
|
||||
|
||||
b.iter(|| ops_sub(&lhs, &rhs));
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
|
||||
Reference in New Issue
Block a user