diff --git a/.github/workflows/ci.yml b/.github/workflows/performance.yml similarity index 89% rename from .github/workflows/ci.yml rename to .github/workflows/performance.yml index 125d844..2b31af0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/performance.yml @@ -1,4 +1,4 @@ -name: C++ CI +name: Performance Benchmarks on: push: @@ -6,7 +6,7 @@ on: pull_request: jobs: - build: + benchmark: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -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 diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 0000000..80b47b1 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d2168e..b1eb076 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/bitvector.hpp b/bitvector.hpp index aaf193b..b6b6b66 100644 --- a/bitvector.hpp +++ b/bitvector.hpp @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/bitvector_test.cpp b/bitvector_test.cpp index 327d5a5..a7e6f86 100644 --- a/bitvector_test.cpp +++ b/bitvector_test.cpp @@ -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;