Skip to content

Commit 2ad5a98

Browse files
committed
NONE: Prepare the library benchmarking subproject layout
- Added the `benchmarks` directory containing the initial library benchmarks implementation - Defined the benchmark suite and runner classes responsible for proper setup and execution of CPP-GL benchmarks - Implemented a simple benchmark: bipartiteness verification of a K_n,n biclique - Added the `benchmarks` smoke test workflow
1 parent 507f8fd commit 2ad5a98

19 files changed

Lines changed: 472 additions & 12 deletions

File tree

.clangd

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
CompileFlags:
2+
CompilationDatabase: build
23
Add:
34
- -std=c++23
45
- -xc++-header
56
- -Iinclude
6-
- -Itests/include
7-
- -Itests/external
87
- -Wall
98
- -Wextra
9+
- -Wcast-align
10+
- -Wconversion
11+
- -Wsign-conversion
12+
- -Wunreachable-code
13+
- -Wuninitialized
14+
- -Wunused
15+
- -pedantic
1016
- -ftemplate-depth=512
1117

1218
Diagnostics:
@@ -21,3 +27,21 @@ Diagnostics:
2127

2228
Index:
2329
Background: Build
30+
31+
---
32+
33+
If:
34+
PathMatch: tests/.*
35+
CompileFlags:
36+
Add:
37+
- -Itests/include
38+
- -Itests/external
39+
40+
---
41+
42+
If:
43+
PathMatch: benchmarks/.*
44+
CompileFlags:
45+
CompilationDatabase: build_bench
46+
Add:
47+
- -Ibenchmarks/include

.github/workflows/benchmarks.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Benchmarks Smoke Test
2+
on:
3+
push:
4+
branches:
5+
- "*"
6+
paths:
7+
- .github/workflows/benchmarks.yaml
8+
- CMakeLists.txt
9+
- cmake/
10+
- include/**
11+
- benchmarks/**
12+
13+
jobs:
14+
build:
15+
name: Build and run benchmarks
16+
runs-on: ubuntu-24.04
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Install Dependencies (Boost)
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y libboost-graph-dev
26+
27+
- name: Prepare
28+
env:
29+
CC: gcc-14
30+
CXX: g++-14
31+
run: |
32+
cmake -B build_bench \
33+
-DBUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
34+
continue-on-error: false
35+
36+
- name: Build the benchmarks
37+
run: |
38+
cmake --build build_bench/ -j$(nproc)
39+
continue-on-error: false
40+
41+
- name: Execute the smoke test
42+
run: |
43+
./build_bench/benchmarks/gl_benchmarks \
44+
--benchmark_repetitions=1 --benchmark_display_aggregates_only=true \
45+
--bip-v 100

.github/workflows/clang.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
name: clang++
1+
name: Clang++
22
on:
33
push:
44
branches:
55
- "*"
66
paths:
77
- .github/workflows/clang.yaml
8+
- CMakeLists.txt
9+
- cmake/
810
- include/**
911
- tests/**
1012

@@ -27,7 +29,7 @@ jobs:
2729

2830
- name: Build test executable
2931
run: |
30-
cmake --build build_clang/ -j5
32+
cmake --build build_clang/ -j$(nproc)
3133
continue-on-error: false
3234

3335
- name: Run tests

.github/workflows/format.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
name: format
1+
name: Code Formatting
22
on:
33
push:
44
branches:
55
- "*"
66
paths:
77
- .github/workflows/format.yaml
8+
- scripts/common.py
89
- scripts/format.py
910
- include/**
1011
- tests/include/**
1112
- tests/source/**
1213
- tests/app/**
14+
- benchmarks/**
1315

1416
jobs:
1517
build:

.github/workflows/gpp.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
name: g++
1+
name: G++
22
on:
33
push:
44
branches:
55
- "*"
66
paths:
77
- .github/workflows/gpp.yaml
8+
- CMakeLists.txt
9+
- cmake/
810
- include/**
911
- tests/**
1012

@@ -27,7 +29,7 @@ jobs:
2729

2830
- name: Build test executable
2931
run: |
30-
cmake --build build_gcc/ -j5
32+
cmake --build build_gcc/ -j$(nproc)
3133
continue-on-error: false
3234

3335
- name: Run tests

.github/workflows/licence.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
name: licence
1+
name: Licence
22
on:
33
push:
44
branches:
55
- "*"
66
paths:
77
- .github/workflows/licence.yaml
8+
- scripts/common.py
89
- scripts/check_licence.py
910
- include/**
1011

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ project(cpp-gl
1717
set(MIN_CXX_STANDARD 23)
1818
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1919
option(BUILD_TESTS "Build project tests" OFF)
20+
option(BUILD_BENCHMARKS "Build project benchmarks" OFF)
2021

2122
# Set the proper cxx standard
2223
if(NOT DEFINED CMAKE_CXX_STANDARD)
@@ -88,3 +89,8 @@ export(PACKAGE cpp-gl)
8889
if (CPP_GL_IS_TOP_LEVEL_PROJECT AND BUILD_TESTS)
8990
add_subdirectory(tests)
9091
endif()
92+
93+
# Include test directory if cpp-gl is a top level project
94+
if (CPP_GL_IS_TOP_LEVEL_PROJECT AND BUILD_BENCHMARKS)
95+
add_subdirectory(benchmarks)
96+
endif()

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[![g++](https://github.com/SpectraL519/cpp-gl/actions/workflows/gpp.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/g++)
1212
[![clang++](https://github.com/SpectraL519/cpp-gl/actions/workflows/clang.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/clang++)
1313
[![format](https://github.com/SpectraL519/cpp-gl/actions/workflows/format.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/format)
14+
[![benchmarks](https://github.com/SpectraL519/cpp-gl/actions/workflows/benchmarks.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/benchmarks.yaml)
1415

1516
</div>
1617

benchmarks/CMakeLists.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(gl_benchmarks LANGUAGES CXX)
3+
4+
include(FetchContent)
5+
6+
# Build options
7+
set(BENCH_GL_DEFS "" CACHE STRING "Additional compile definitions for the CPP-GL target")
8+
set(BENCH_OPT_MODE "3" CACHE STRING "The optimisation mode used to build the project benchmarks (default: 3)")
9+
10+
message(STATUS "Build options:")
11+
message(STATUS "[BENCH_GL_DEFS = ${BENCH_GL_DEFS}]")
12+
message(STATUS "[BENCH_OPT_MODE = ${BENCH_OPT_MODE}]")
13+
14+
# Fetch Google Benchmark
15+
FetchContent_Declare(
16+
googlebenchmark
17+
GIT_REPOSITORY https://github.com/google/benchmark.git
18+
GIT_TAG v1.8.3
19+
)
20+
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark tests" FORCE)
21+
FetchContent_MakeAvailable(googlebenchmark)
22+
23+
# Fetch CPP-ARGON
24+
FetchContent_Declare(
25+
cpp-argon
26+
GIT_REPOSITORY https://github.com/SpectraL519/cpp-argon.git
27+
GIT_TAG v4.0.0
28+
)
29+
FetchContent_MakeAvailable(cpp-argon)
30+
31+
# Find Boost for BGL comparisons
32+
find_package(Boost CONFIG REQUIRED)
33+
34+
add_executable(gl_benchmarks
35+
source/main.cpp
36+
source/runner.cpp
37+
suites/is_bipartite.cpp
38+
)
39+
40+
target_compile_options(gl_benchmarks PRIVATE
41+
-Werror
42+
-Wall
43+
-Wextra
44+
-Wcast-align
45+
-Wconversion
46+
-Wsign-conversion
47+
-Wunreachable-code
48+
-Wuninitialized
49+
-Wunused
50+
-pedantic
51+
-O${BENCH_OPT_MODE}
52+
)
53+
54+
target_include_directories(gl_benchmarks PRIVATE include)
55+
target_link_libraries(gl_benchmarks PRIVATE
56+
benchmark::benchmark
57+
cpp-argon
58+
cpp-gl
59+
Boost::headers
60+
)
61+
62+
if(BENCH_GL_DEFS)
63+
separate_arguments(BENCH_GL_DEFS_LIST NATIVE_COMMAND "${BENCH_GL_DEFS}")
64+
target_compile_definitions(gl_benchmarks PRIVATE ${BENCH_GL_DEFS_LIST})
65+
endif()

benchmarks/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# CPP-GL Benchmarks
2+
3+
Building the benchmarks:
4+
5+
```shell
6+
cmake -B build_bench -DBUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release
7+
cmake --build build_bench/ # -j<n>
8+
```
9+
10+
> [!NOTE]
11+
> The benchmarks require having the Boost Graph Library installed.
12+
> To install the library you can use
13+
14+
Running the benchmarks (example):
15+
16+
```shell
17+
./build_bench/benchmarks/gl_benchmarks --bip-v 9000 --benchmark_repetitions=10 --benchmark_display_aggregates_only=true
18+
```

0 commit comments

Comments
 (0)