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
48 changes: 48 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CodSpeed

on:
push:
branches:
- main
- newdev
pull_request:
workflow_dispatch:

permissions:
contents: read
id-token: write

jobs:
benchmarks:
name: Run benchmarks
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq \
build-essential cmake git \
libboost-all-dev libusb-1.0-0-dev libssl-dev \
libprotobuf-dev protobuf-compiler

- name: Build benchmarks
run: |
mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DAASDK_TEST=OFF \
-DAASDK_BENCHMARK=ON \
-DCODSPEED_MODE=simulation \
-DSKIP_BUILD_PROTOBUF=ON \
-DSKIP_BUILD_ABSL=ON \
..
make -j$(nproc) aasdk_benchmarks

- name: Run benchmarks
uses: CodSpeedHQ/action@v4
with:
mode: simulation
run: ./build/bin/aasdk_benchmarks
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ option(SKIP_BUILD_PROTOBUF "Skip building protobuf, use system-installed version
option(SKIP_BUILD_ABSL "Skip building Abseil, use system-installed version" OFF)
option(AASDK_TEST "Build AASDK unit tests" ON)
option(AASDK_CODE_COVERAGE "Enable coverage build options for AASDK tests" OFF)
option(AASDK_BENCHMARK "Build AASDK benchmarks" OFF)

# Cross Compiling Architecture and Package Architecture Detection
if( TARGET_ARCH STREQUAL "amd64" )
Expand Down Expand Up @@ -476,6 +477,10 @@ if(AASDK_TEST)
endif(AASDK_CODE_COVERAGE)
endif(AASDK_TEST)

if(AASDK_BENCHMARK)
add_subdirectory(benchmarks)
endif(AASDK_BENCHMARK)


# CPack Configuration for DEB packages
set(CPACK_GENERATOR "DEB")
Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
[![Build Status](https://img.shields.io/badge/build-passing-brightgreen)](BUILD.md)
[![Documentation](https://img.shields.io/badge/docs-comprehensive-blue)](DOCUMENTATION.md)
[![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/opencardev/aasdk?utm_source=badge)

## Overview

Expand Down
31 changes: 31 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.16)

include(FetchContent)

set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON)

FetchContent_Declare(
google_benchmark
GIT_REPOSITORY https://github.com/CodSpeedHQ/codspeed-cpp
SOURCE_SUBDIR google_benchmark
GIT_TAG main
)

FetchContent_MakeAvailable(google_benchmark)

add_executable(aasdk_benchmarks
bench_messenger.cpp
bench_data.cpp
)

target_link_libraries(aasdk_benchmarks
PRIVATE
benchmark::benchmark
aasdk
)

target_include_directories(aasdk_benchmarks
PRIVATE
${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}/include
)
137 changes: 137 additions & 0 deletions benchmarks/bench_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#include <cstring>
#include <benchmark/benchmark.h>

#include <aasdk/Common/Data.hpp>

using namespace aasdk::common;

// -- DataConstBuffer construction benchmarks --

static void BM_DataConstBufferFromVector(benchmark::State &state) {
Data data(state.range(0), 0x42);

for (auto _ : state) {
DataConstBuffer buffer(data);
benchmark::DoNotOptimize(buffer.cdata);
benchmark::DoNotOptimize(buffer.size);
}
}
BENCHMARK(BM_DataConstBufferFromVector)->Range(64, 65536);

static void BM_DataConstBufferWithOffset(benchmark::State &state) {
Data data(4096, 0x42);

for (auto _ : state) {
DataConstBuffer buffer(data, 128);
benchmark::DoNotOptimize(buffer.cdata);
benchmark::DoNotOptimize(buffer.size);
}
}
BENCHMARK(BM_DataConstBufferWithOffset);

// -- Data copy benchmarks --

static void BM_DataCopySmall(benchmark::State &state) {
Data source(64, 0xAB);
DataConstBuffer buffer(source);

for (auto _ : state) {
Data dest;
copy(dest, buffer);
benchmark::DoNotOptimize(dest);
benchmark::ClobberMemory();
}
}
BENCHMARK(BM_DataCopySmall);

static void BM_DataCopy(benchmark::State &state) {
Data source(state.range(0), 0xAB);
DataConstBuffer buffer(source);

for (auto _ : state) {
Data dest;
copy(dest, buffer);
benchmark::DoNotOptimize(dest);
benchmark::ClobberMemory();
}
}
BENCHMARK(BM_DataCopy)->Range(256, 1 << 20);

static void BM_DataCopyAppend(benchmark::State &state) {
Data source(1024, 0xCD);
DataConstBuffer buffer(source);

for (auto _ : state) {
Data dest;
dest.reserve(4096);
for (int i = 0; i < 4; ++i) {
copy(dest, buffer);
}
benchmark::DoNotOptimize(dest);
benchmark::ClobberMemory();
}
}
BENCHMARK(BM_DataCopyAppend);

// -- createData benchmark --

static void BM_CreateData(benchmark::State &state) {
Data source(state.range(0), 0xEF);
DataConstBuffer buffer(source);

for (auto _ : state) {
Data result = createData(buffer);
benchmark::DoNotOptimize(result);
benchmark::ClobberMemory();
}
}
BENCHMARK(BM_CreateData)->Range(64, 65536);

// -- Data dump (hex encoding) benchmarks --

static void BM_DataDump(benchmark::State &state) {
Data data(state.range(0), 0xAB);

for (auto _ : state) {
std::string result = dump(data);
benchmark::DoNotOptimize(result);
benchmark::ClobberMemory();
}
}
BENCHMARK(BM_DataDump)->Range(16, 4096);

static void BM_DataDumpBuffer(benchmark::State &state) {
Data data(state.range(0), 0xCD);
DataConstBuffer buffer(data);

for (auto _ : state) {
std::string result = dump(buffer);
benchmark::DoNotOptimize(result);
benchmark::ClobberMemory();
}
}
BENCHMARK(BM_DataDumpBuffer)->Range(16, 4096);

// -- DataBuffer equality benchmarks --

static void BM_DataConstBufferEquality(benchmark::State &state) {
Data data(1024, 0x42);
DataConstBuffer buf1(data);
DataConstBuffer buf2(data);

for (auto _ : state) {
bool result = (buf1 == buf2);
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(BM_DataConstBufferEquality);

static void BM_DataConstBufferNullCheck(benchmark::State &state) {
DataConstBuffer buffer;

for (auto _ : state) {
bool result = (buffer == nullptr);
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(BM_DataConstBufferNullCheck);
Loading
Loading