Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
CARGO_INCREMENTAL: 0

jobs:
# Ensure the crate builds
build:

runs-on: ubuntu-latest
Expand All @@ -32,6 +33,7 @@ jobs:
cargo test --verbose --features "$FEATURES" &&
cargo test --verbose --release --features "$FEATURES"

# Use clippy to lint for code smells
clippy:

runs-on: ubuntu-latest
Expand All @@ -52,6 +54,7 @@ jobs:
run: |
cargo clippy

# Enforce rustfmt formatting
formatting:

runs-on: ubuntu-latest
Expand All @@ -70,4 +73,26 @@ jobs:
override: true
- name: Run Clippy
run: |
cargo fmt --all --check
cargo fmt --all --check

# Ensure the benchmarks compile
benchmark_compiles:

runs-on: ubuntu-latest
strategy:
matrix:
# Check builds only on stable
rust: [stable]

steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: ${{ matrix.rust }}
components: clippy
override: true
- name: Run Clippy
run: |
cd benches
cargo bench --bench benches --no-run
15 changes: 15 additions & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "benches"
version = "0.1.0"
edition = "2021"
description = "Benchmarks for FixedBitset"
publish = false
license = "MIT OR Apache-2.0"

[dev-dependencies]
fixedbitset = { path = ".." }
criterion = { version = "0.4", features = ["html_reports"] }

[[bench]]
name = "benches"
harness = false
131 changes: 0 additions & 131 deletions benches/benches.rs

This file was deleted.

163 changes: 163 additions & 0 deletions benches/benches/benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
extern crate criterion;
extern crate fixedbitset;
use criterion::{criterion_group, criterion_main, Criterion};
use fixedbitset::FixedBitSet;
use std::hint::black_box;

#[inline]
fn iter_ones_using_contains<F: FnMut(usize)>(fb: &FixedBitSet, f: &mut F) {
for bit in 0..fb.len() {
if fb.contains(bit) {
f(bit);
}
}
}

fn iter_ones_using_contains_all_zeros(c: &mut Criterion) {
const N: usize = 1_000_000;
let fb = FixedBitSet::with_capacity(N);

c.bench_function("iter_ones/contains_all_zeros", |b| {
b.iter(|| {
let mut count = 0;
iter_ones_using_contains(&fb, &mut |_bit| count += 1);
count
})
});
}

fn iter_ones_using_contains_all_ones(c: &mut Criterion) {
const N: usize = 1_000_000;
let mut fb = FixedBitSet::with_capacity(N);
fb.insert_range(..);

c.bench_function("iter_ones/contains_all_ones", |b| {
b.iter(|| {
let mut count = 0;
iter_ones_using_contains(&fb, &mut |_bit| count += 1);
count
})
});
}

fn iter_ones_all_zeros(c: &mut Criterion) {
const N: usize = 1_000_000;
let fb = FixedBitSet::with_capacity(N);

c.bench_function("iter_ones/all_zeros", |b| {
b.iter(|| {
let mut count = 0;
for _ in fb.ones() {
count += 1;
}
count
})
});
}

fn iter_ones_all_ones(c: &mut Criterion) {
const N: usize = 1_000_000;
let mut fb = FixedBitSet::with_capacity(N);
fb.insert_range(..);

c.bench_function("iter_ones/all_ones", |b| {
b.iter(|| {
let mut count = 0;
for _ in fb.ones() {
count += 1;
}
count
})
});
}

fn insert_range(c: &mut Criterion) {
const N: usize = 1_000_000;
let mut fb = FixedBitSet::with_capacity(N);

c.bench_function("insert_range/1m", |b| b.iter(|| fb.insert_range(..)));
}

fn insert(c: &mut Criterion) {
const N: usize = 1_000_000;
let mut fb = FixedBitSet::with_capacity(N);

c.bench_function("insert/1m", |b| {
b.iter(|| {
for i in 0..N {
fb.insert(i);
}
})
});
}

fn union_with(c: &mut Criterion) {
const N: usize = 1_000_000;
let mut fb_a = FixedBitSet::with_capacity(N);
let fb_b = FixedBitSet::with_capacity(N);

c.bench_function("union_with/1m", |b| b.iter(|| fb_a.union_with(&fb_b)));
}

fn intersect_with(c: &mut Criterion) {
const N: usize = 1_000_000;
let mut fb_a = FixedBitSet::with_capacity(N);
let fb_b = FixedBitSet::with_capacity(N);

c.bench_function("intersect_with/1m", |b| {
b.iter(|| fb_a.intersect_with(&fb_b))
});
}

fn difference_with(c: &mut Criterion) {
const N: usize = 1_000_000;
let mut fb_a = FixedBitSet::with_capacity(N);
let fb_b = FixedBitSet::with_capacity(N);

c.bench_function("difference_with/1m", |b| {
b.iter(|| fb_a.difference_with(&fb_b))
});
}

fn symmetric_difference_with(c: &mut Criterion) {
const N: usize = 1_000_000;
let mut fb_a = FixedBitSet::with_capacity(N);
let fb_b = FixedBitSet::with_capacity(N);

c.bench_function("symmetric_difference_with/1m", |b| {
b.iter(|| fb_a.symmetric_difference_with(&fb_b))
});
}

fn clear(c: &mut Criterion) {
const N: usize = 1_000_000;
let mut fb_a = FixedBitSet::with_capacity(N);

c.bench_function("clear/1m", |b| b.iter(|| fb_a.clear()));
}

fn count_ones(c: &mut Criterion) {
const N: usize = 1_000_000;
let fb_a = FixedBitSet::with_capacity(N);

c.bench_function("count_ones/1m", |b| {
b.iter(|| black_box(fb_a.count_ones(..)))
});
}

criterion_group!(
benches,
iter_ones_using_contains_all_zeros,
iter_ones_using_contains_all_ones,
iter_ones_all_zeros,
iter_ones_all_ones,
insert_range,
insert,
intersect_with,
difference_with,
union_with,
symmetric_difference_with,
count_ones,
clear,
);
criterion_main!(benches);