Skip to content

Commit 30bf30b

Browse files
authored
Merge pull request #9 from bugparty/codex/separate-unit-and-performance-tests-in-github-actions
Separate unit/performance CI, optional bounds check
2 parents 5ba993d + 34b567f commit 30bf30b

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: C++ CI
1+
name: Performance Benchmarks
22

33
on:
44
push:
55
branches: ["main"]
66
pull_request:
77

88
jobs:
9-
build:
9+
benchmark:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v3
@@ -16,8 +16,6 @@ jobs:
1616
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
1717
- name: Build
1818
run: cmake --build build --config Release
19-
- name: Run tests
20-
run: ctest --test-dir build --output-on-failure
2119
- name: Run benchmarks
2220
run: ./build/bitvector_benchmark --benchmark_min_time=0.01s
2321
- name: Dump benchmark assembly

.github/workflows/unit_tests.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Install dependencies
14+
run: sudo apt-get update && sudo apt-get install -y build-essential cmake
15+
- name: Configure
16+
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
17+
- name: Build
18+
run: cmake --build build --config Release
19+
- name: Run tests
20+
run: ctest --test-dir build --output-on-failure

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ elseif(MSVC)
3434
message(WARNING "BMI1 support is not available for MSVC in this configuration.")
3535
endif()
3636

37+
# Optionally disable bounds checking in the bitvector implementation
38+
option(BITVECTOR_ENABLE_BOUND_CHECK "Enable bounds checking in bitvector" OFF)
39+
if(NOT BITVECTOR_ENABLE_BOUND_CHECK)
40+
add_compile_definitions(BITVECTOR_NO_BOUND_CHECK)
41+
endif()
42+
3743
# Enable testing
3844
enable_testing()
3945

bitvector.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ namespace bowen
208208

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

224224
bool operator[](size_t pos) const
225225
{
226-
#ifndef BITVECTOR_DISABLE_BOUNDS_CHECK
226+
#ifndef BITVECTOR_NO_BOUND_CHECK
227227
if (pos >= m_size){
228228
std::stringstream ss;
229229
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
@@ -235,7 +235,7 @@ namespace bowen
235235
return (m_data[word_index] & mask) != 0;
236236
}
237237
inline void set_bit(size_t pos, bool value){
238-
#ifndef BITVECTOR_DISABLE_BOUNDS_CHECK
238+
#ifndef BITVECTOR_NO_BOUND_CHECK
239239
if (pos >= m_size){
240240
std::stringstream ss;
241241
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
@@ -322,7 +322,7 @@ namespace bowen
322322
}
323323
void incrementUntilZero(size_t& pos){
324324
// Ensure the position is within bounds
325-
#ifndef BITVECTOR_DISABLE_BOUNDS_CHECK
325+
#ifndef BITVECTOR_NO_BOUND_CHECK
326326
if (pos >= m_size){
327327
std::stringstream ss;
328328
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;

bitvector_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ TEST(BitvectorTest, ConstructWithValue) {
3737
}
3838
}
3939

40+
#ifndef BITVECTOR_NO_BOUND_CHECK
4041
TEST(BitvectorTest, OutOfRangeThrows) {
4142
bowen::bitvector<> bv(5);
4243
EXPECT_THROW(bv[5], std::out_of_range);
4344
EXPECT_THROW(bv.set_bit(5, true), std::out_of_range);
4445
}
46+
#endif
4547

4648
TEST(BitvectorTest, CopyAndAssignment) {
4749
bowen::bitvector<> bv1;

0 commit comments

Comments
 (0)