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
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: C++ CI
name: Performance Benchmarks

on:
push:
branches: ["main"]
pull_request:

jobs:
build:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -16,8 +16,6 @@ jobs:
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
- name: Build
run: cmake --build build --config Release
- name: Run tests
run: ctest --test-dir build --output-on-failure
- name: Run benchmarks
run: ./build/bitvector_benchmark --benchmark_min_time=0.01s
- name: Dump benchmark assembly
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Unit Tests

on:
push:
branches: ["main"]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y build-essential cmake
- name: Configure
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
- name: Build
run: cmake --build build --config Release
- name: Run tests
run: ctest --test-dir build --output-on-failure
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ elseif(MSVC)
message(WARNING "BMI1 support is not available for MSVC in this configuration.")
endif()

# Optionally disable bounds checking in the bitvector implementation
option(BITVECTOR_ENABLE_BOUND_CHECK "Enable bounds checking in bitvector" OFF)
if(NOT BITVECTOR_ENABLE_BOUND_CHECK)
add_compile_definitions(BITVECTOR_NO_BOUND_CHECK)
endif()

# Enable testing
enable_testing()

Expand Down
8 changes: 4 additions & 4 deletions bitvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ namespace bowen

reference operator[](size_t pos)
{
#ifndef BITVECTOR_DISABLE_BOUNDS_CHECK
#ifndef BITVECTOR_NO_BOUND_CHECK
if (pos >= m_size){
std::stringstream ss;
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
Expand All @@ -223,7 +223,7 @@ namespace bowen

bool operator[](size_t pos) const
{
#ifndef BITVECTOR_DISABLE_BOUNDS_CHECK
#ifndef BITVECTOR_NO_BOUND_CHECK
if (pos >= m_size){
std::stringstream ss;
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
Expand All @@ -235,7 +235,7 @@ namespace bowen
return (m_data[word_index] & mask) != 0;
}
inline void set_bit(size_t pos, bool value){
#ifndef BITVECTOR_DISABLE_BOUNDS_CHECK
#ifndef BITVECTOR_NO_BOUND_CHECK
if (pos >= m_size){
std::stringstream ss;
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
Expand Down Expand Up @@ -322,7 +322,7 @@ namespace bowen
}
void incrementUntilZero(size_t& pos){
// Ensure the position is within bounds
#ifndef BITVECTOR_DISABLE_BOUNDS_CHECK
#ifndef BITVECTOR_NO_BOUND_CHECK
if (pos >= m_size){
std::stringstream ss;
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
Expand Down
2 changes: 2 additions & 0 deletions bitvector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ TEST(BitvectorTest, ConstructWithValue) {
}
}

#ifndef BITVECTOR_NO_BOUND_CHECK
TEST(BitvectorTest, OutOfRangeThrows) {
bowen::bitvector<> bv(5);
EXPECT_THROW(bv[5], std::out_of_range);
EXPECT_THROW(bv.set_bit(5, true), std::out_of_range);
}
#endif

TEST(BitvectorTest, CopyAndAssignment) {
bowen::bitvector<> bv1;
Expand Down