Skip to content

Commit

Permalink
bench: add simd bitvec benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
PsiACE committed Feb 15, 2022
1 parent dbfbbe3 commit e0ea40c
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ std = []

[dev-dependencies]
criterion = "0.3"
# for normal bench
bit-vec = "0.6"
bitvec = "1.0.0"
# for simd bench
wide = "0.7.4"
bitvec_simd = "0.15.0"
bitvector_simd = "0.2.2"

[[bench]]
name = "comparison"
Expand Down
114 changes: 114 additions & 0 deletions benches/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,110 @@ fn benchmark_bitvector_simd4_u16x8(c: &mut Criterion) {
});
}

fn benchmark_bitvector_bitvec_simd(c: &mut Criterion) {
let b1 = bitvec_simd::BitVec::ones(100_000);
let b2 = bitvec_simd::BitVec::zeros(100_000);
c.bench_function("bitvec_simd 0.15.0", |b| {
b.iter(|| {
black_box(b1.and_cloned(&b2));
})
});
}

fn benchmark_bitvector_bitvec_simd2(c: &mut Criterion) {
c.bench_function("bitvec_simd 0.15.0 with creation", |b| {
b.iter(|| {
let b1 = bitvec_simd::BitVec::ones(100_000);
let b2 = bitvec_simd::BitVec::zeros(100_000);
black_box(b1.and(b2));
})
});
}

fn benchmark_bitvector_bitvec_simd3(c: &mut Criterion) {
c.bench_function("bitvec_simd 0.15.0 resize false", |b| {
b.iter(|| {
let mut b1 = bitvec_simd::BitVec::ones(100_000);
black_box(b1.resize(200_000, false));
})
});
}

fn benchmark_bitvector_bitvec_simd4(c: &mut Criterion) {
c.bench_function("bitvec_simd 0.15.0 resize true", |b| {
b.iter(|| {
let mut b1 = bitvec_simd::BitVec::ones(100_000);
black_box(b1.resize(200_000, true));
})
});
}

fn benchmark_bitvector_bitvec_simd_u16x8(c: &mut Criterion) {
use wide::*;

let b1 = bitvec_simd::BitVecSimd::<[u16x8; 4], 8>::ones(100_000);
let b2 = bitvec_simd::BitVecSimd::<[u16x8; 4], 8>::zeros(100_000);
c.bench_function("bitvec_simd 0.15.0 u16x8", |b| {
b.iter(|| {
black_box(b1.and_cloned(&b2));
})
});
}

fn benchmark_bitvector_bitvec_simd2_u16x8(c: &mut Criterion) {
use wide::*;

c.bench_function("bitvec_simd 0.15.0 u16x8 with creation", |b| {
b.iter(|| {
let b1 = bitvec_simd::BitVecSimd::<[u16x8; 4], 8>::ones(100_000);
let b2 = bitvec_simd::BitVecSimd::<[u16x8; 4], 8>::zeros(100_000);
black_box(b1.and(b2));
})
});
}

fn benchmark_bitvector_bitvec_simd3_u16x8(c: &mut Criterion) {
use wide::*;

c.bench_function("bitvec_simd 0.15.0 u16x8 resize false", |b| {
b.iter(|| {
let mut b1 = bitvec_simd::BitVecSimd::<[u16x8; 4], 8>::ones(100_000);
black_box(b1.resize(200_000, false));
})
});
}

fn benchmark_bitvector_bitvec_simd4_u16x8(c: &mut Criterion) {
use wide::*;

c.bench_function("bitvec_simd 0.15.0 u16x8 resize true", |b| {
b.iter(|| {
let mut b1 = bitvec_simd::BitVecSimd::<[u16x8; 4], 8>::ones(100_000);
black_box(b1.resize(200_000, true));
})
});
}

fn benchmark_bitvector_bitvector_simd(c: &mut Criterion) {
let b1 = bitvector_simd::BitVector::ones(100_000);
let b2 = bitvector_simd::BitVector::zeros(100_000);
c.bench_function("bitvector_simd 0.2.2", |b| {
b.iter(|| {
black_box(b1.and_cloned(&b2));
})
});
}

fn benchmark_bitvector_bitvector_simd2(c: &mut Criterion) {
c.bench_function("bitvector_simd 0.2.2 with creation", |b| {
b.iter(|| {
let b1 = bitvector_simd::BitVector::ones(100_000);
let b2 = bitvector_simd::BitVector::zeros(100_000);
black_box(b1.and(b2));
})
});
}

fn benchmark_bitvector_bitvec(c: &mut Criterion) {
let b1 = bit_vec::BitVec::from_elem(100_000, true);
let b2 = bit_vec::BitVec::from_elem(100_000, false);
Expand Down Expand Up @@ -141,26 +245,36 @@ criterion_group!(
normal_benches,
benchmark_bitvector_simd,
benchmark_bitvector_simd_u16x8,
benchmark_bitvector_bitvec_simd,
benchmark_bitvector_bitvec_simd_u16x8,
benchmark_bitvector_bitvector_simd,
benchmark_bitvector_bitvec,
benchmark_bitvector_bitvec_n
);
criterion_group!(
with_creation_benches,
benchmark_bitvector_simd2,
benchmark_bitvector_simd2_u16x8,
benchmark_bitvector_bitvec_simd2,
benchmark_bitvector_bitvec_simd2_u16x8,
benchmark_bitvector_bitvector_simd2,
benchmark_bitvector_bitvec2,
benchmark_bitvector_bitvec_n2
);
criterion_group!(
resize_false_benches,
benchmark_bitvector_simd3,
benchmark_bitvector_simd3_u16x8,
benchmark_bitvector_bitvec_simd3,
benchmark_bitvector_bitvec_simd3_u16x8,
benchmark_bitvector_bitvec_n3
);
criterion_group!(
resize_true_benches,
benchmark_bitvector_simd4,
benchmark_bitvector_simd4_u16x8,
benchmark_bitvector_bitvec_simd4,
benchmark_bitvector_bitvec_simd4_u16x8,
benchmark_bitvector_bitvec_n4
);
criterion_main!(
Expand Down

0 comments on commit e0ea40c

Please sign in to comment.