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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repository provides a small bit vector implementation along with tests and

## Running the benchmarks without bounds checking

Bounds checking is enabled by default. To benchmark without checks, configure and build with:
Bounds checking is enabled by default. To benchmark without checks, configure and build with (this defines `BITVECTOR_NO_BOUND_CHECK`):

```bash
cmake -S . -B build -DBITVECTOR_NO_BOUND_CHECK=ON -DCMAKE_BUILD_TYPE=Release
Expand Down
77 changes: 77 additions & 0 deletions bitvector_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,88 @@ static void BM_Std_Access(benchmark::State& state) {
}
}


static void BM_Bowen_SetBitTrue6(benchmark::State& state) {
size_t n = state.range(0);
for (auto _ : state) {
bitvector<> bv(n);
for (size_t pos=0; pos+5 < n; pos+=6) {
bv.set_bit_true_6(pos, 1);
}
benchmark::ClobberMemory();
}
}

static void BM_Std_SetBitTrue6(benchmark::State& state) {
size_t n = state.range(0);
for (auto _ : state) {
std::vector<bool> bv(n);
for (size_t pos=0; pos+5 < n; pos+=6) {
for (int i=0;i<6;++i) {
bv[pos+i] = true;
}
}
benchmark::ClobberMemory();
}
}

static void BM_Bowen_QSetBitTrue6V2(benchmark::State& state) {
size_t n = state.range(0);
for (auto _ : state) {
bitvector<> bv(n);
bv.qset_bit_true_6_v2(0, 1, n);
benchmark::ClobberMemory();
}
}

static void BM_Std_QSetBitTrue6(benchmark::State& state) {
size_t n = state.range(0);
for (auto _ : state) {
std::vector<bool> bv(n);
for (size_t i=0;i<n;++i) {
bv[i] = true;
}
benchmark::ClobberMemory();
}
}

static void BM_Bowen_IncrementUntilZero(benchmark::State& state) {
size_t n = state.range(0);
bitvector<> bv(n, true);
bv.set_bit(n-1, false);
for (auto _ : state) {
size_t pos = 0;
bv.incrementUntilZero(pos);
benchmark::DoNotOptimize(pos);
}
}

static void incrementUntilZeroStd(const std::vector<bool>& bv, size_t& pos) {
while (pos < bv.size() && bv[pos]) ++pos;
}

static void BM_Std_IncrementUntilZero(benchmark::State& state) {
size_t n = state.range(0);
std::vector<bool> bv(n, true);
bv[n-1] = false;
for (auto _ : state) {
size_t pos = 0;
incrementUntilZeroStd(bv, pos);
benchmark::DoNotOptimize(pos);
}
}

BENCHMARK(BM_Bowen_Set)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Std_Set)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Bowen_PushBack)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Std_PushBack)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Bowen_Access)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Std_Access)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Bowen_SetBitTrue6)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Std_SetBitTrue6)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Bowen_QSetBitTrue6V2)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Std_QSetBitTrue6)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Bowen_IncrementUntilZero)->Arg(1<<20)->MinTime(5.0);
BENCHMARK(BM_Std_IncrementUntilZero)->Arg(1<<20)->MinTime(5.0);

BENCHMARK_MAIN();
5 changes: 4 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include <chrono>
#include <iostream>
#include <vector>
constexpr size_t SIZE = 1000000000; // 1 billion elements

// Benchmark size: 1 billion elements
constexpr size_t SIZE = 1000000000;

// Benchmarks the performance of std::vector<bool> for setting, accessing, and traversing elements.
void benchmarkStdVectorBool(){

Expand Down