Skip to content
Open
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
71 changes: 66 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ ubuntu-latest, macos-latest, windows-latest ]

runs-on: ${{ matrix.os }}
continue-on-error: true
Expand All @@ -34,22 +34,83 @@ jobs:
submodules: recursive

- name: Install Packages (Ubuntu)
run: |
sudo apt-get install -y uuid-dev
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y uuid-dev

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dflow-core_BUILD_TESTS=ON
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dflow-core_BUILD_TESTS=ON -Dflow-core_BUILD_BENCHMARKS=ON

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel 18
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel 10

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: Test Module (${{matrix.os}})
path: ${{github.workspace}}/build/tests/test_module.fmod

- name: Cache Build Output
uses: actions/cache@v4
with:
path: ${{github.workspace}}/build
key: ${{matrix.os}}-build-${{github.sha}}

test:
needs: build
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]

runs-on: ${{ matrix.os }}
continue-on-error: true

steps:
- uses: actions/checkout@v4
- name: Restore build output cache
uses: actions/cache@v4
with:
path: ${{github.workspace}}/build
key: ${{matrix.os}}-build-${{github.sha}}

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure

benchmark:
needs: build
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]

runs-on: ${{ matrix.os }}
continue-on-error: true
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Restore build output cache
uses: actions/cache@v4
with:
path: ${{github.workspace}}/build
key: ${{matrix.os}}-build-${{github.sha}}

- name: Benchmark
run: ${{github.workspace}}/build/benchmarks/${{ matrix.os == 'windows-latest' && env.BUILD_TYPE || '' }}/flow_core_bench

cleanup_cache:
needs: [test, benchmark]
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]

runs-on: ${{ matrix.os }}
continue-on-error: true
permissions: write-all
timeout-minutes: 10
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}

if: always() # Run even if previous jobs failed
steps:
- name: Delete Cache
run: gh cache delete ${{matrix.os}}-build-${{github.sha}}
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

cmake_minimum_required(VERSION 3.10)

set (CMAKE_POLICY_VERSION_MINIMUM 3.5)

project(flow-core VERSION 1.1.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
Expand All @@ -19,6 +21,7 @@ endif()
# -----------------------------------------------------------------------------

option(${PROJECT_NAME}_BUILD_TESTS "Build tests (gtest)" OFF)
option(${PROJECT_NAME}_BUILD_BENCHMARKS "Build benchmarks (googlebenchmark)" OFF)
option(${PROJECT_NAME}_BUILD_TOOLS "Build tools" OFF)
option(${PROJECT_NAME}_INSTALL "Add installation targets" OFF)

Expand Down Expand Up @@ -152,6 +155,14 @@ if (${PROJECT_NAME}_BUILD_TESTS)
add_subdirectory(tests)
endif()

# -----------------------------------------------------------------------------
# Benchmarks
# -----------------------------------------------------------------------------

if (${PROJECT_NAME}_BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()

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

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#=============================================================================#
# Dependencies
#=============================================================================#

set(BENCHMARK_USE_BUNDLED_GTEST OFF)
set(BENCHMARK_ENABLE_TESTING OFF)
CPMAddPackage("gh:google/benchmark@1.9.4")

#=============================================================================#
# Test Executable
#=============================================================================#

set(BENCH_EXE flow_core_bench)
add_executable(
${BENCH_EXE}

event_bench.cpp
graph_bench.cpp
indexable_name_bench.cpp
node_data_bench.cpp
type_name_bench.cpp
uuid_bench.cpp
)

if(MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
target_compile_options(${BENCH_EXE} PRIVATE /W4 /MP)
endif()

target_link_libraries(${BENCH_EXE} PRIVATE
flow-core::flow-core
benchmark::benchmark_main
)

target_include_directories(${BENCH_EXE} PRIVATE
${CMAKE_SOURCE_DIR}/include/flow/core
${thread_pool_SOURCE_DIR}/include
)

if(MSVC)
add_custom_command(TARGET ${BENCH_EXE} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:${PROJECT_NAME}>
$<TARGET_FILE_DIR:${BENCH_EXE}>
)
endif()
49 changes: 49 additions & 0 deletions benchmarks/event_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2025, Cisco Systems, Inc.
// All rights reserved.

#include <benchmark/benchmark.h>

#include <flow/core/Env.hpp>
#include <flow/core/Event.hpp>
#include <flow/core/IndexableName.hpp>
#include <flow/core/NodeFactory.hpp>

#include <array>
#include <string>

static void EventDispatcher_BroadcastBrutal(benchmark::State& state)
{
flow::EventDispatcher<> dispatcher;
std::array<std::string, 1000> names;

for (int i = 0; i < names.size(); ++i)
{
names[i] = "Event_" + std::to_string(i);
dispatcher.Bind(flow::IndexableName{names[i]}, [&] { ++i; });
}

for ([[maybe_unused]] const auto& _ : state)
{
dispatcher.Broadcast();
}
}

static void EventDispatcher_BroadcastRealistic(benchmark::State& state)
{
flow::EventDispatcher<> dispatcher;
std::array<std::string, 10> names;

for (int i = 0; i < names.size(); ++i)
{
names[i] = "Event_" + std::to_string(i);
dispatcher.Bind(flow::IndexableName{names[i]}, [&] { ++i; });
}

for ([[maybe_unused]] const auto& _ : state)
{
dispatcher.Broadcast();
}
}

BENCHMARK(EventDispatcher_BroadcastBrutal);
BENCHMARK(EventDispatcher_BroadcastRealistic);
23 changes: 23 additions & 0 deletions benchmarks/graph_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2025, Cisco Systems, Inc.
// All rights reserved.

#include <benchmark/benchmark.h>

#include <flow/core/Env.hpp>
#include <flow/core/FunctionNode.hpp>
#include <flow/core/Graph.hpp>
#include <flow/core/NodeFactory.hpp>

#include <cmath>

static void Graph_Construct(benchmark::State& state)
{
auto factory = flow::NodeFactory::Create();
auto env = flow::Env::Create(factory);
for ([[maybe_unused]] const auto& _ : state)
{
flow::Graph("benchmark", env);
}
}

BENCHMARK(Graph_Construct);
26 changes: 26 additions & 0 deletions benchmarks/indexable_name_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2025, Cisco Systems, Inc.
// All rights reserved.

#include <benchmark/benchmark.h>

#include <flow/core/IndexableName.hpp>

static void IndexableName_Construct(benchmark::State& state)
{
for ([[maybe_unused]] const auto& _ : state)
{
benchmark::DoNotOptimize(flow::IndexableName{"benchmark"});
}
}

static void IndexableName_Hash(benchmark::State& state)
{
constexpr flow::IndexableName name{"benchmark"};
for ([[maybe_unused]] const auto& _ : state)
{
benchmark::DoNotOptimize(std::hash<flow::IndexableName>{}(name));
}
}

BENCHMARK(IndexableName_Construct);
BENCHMARK(IndexableName_Hash);
29 changes: 29 additions & 0 deletions benchmarks/node_data_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2025, Cisco Systems, Inc.
// All rights reserved.

#include <benchmark/benchmark.h>

#include <flow/core/NodeData.hpp>

static void NodeData_Construct(benchmark::State& state)
{
for ([[maybe_unused]] const auto& _ : state)
{
flow::NodeData<int> data;
benchmark::DoNotOptimize(data);
benchmark::ClobberMemory();
}
}

static void NodeData_ConstructShared(benchmark::State& state)
{
for ([[maybe_unused]] const auto& _ : state)
{
auto data = flow::MakeNodeData<int>(0);
benchmark::DoNotOptimize(data);
benchmark::ClobberMemory();
}
}

BENCHMARK(NodeData_Construct);
BENCHMARK(NodeData_ConstructShared);
18 changes: 18 additions & 0 deletions benchmarks/type_name_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2025, Cisco Systems, Inc.
// All rights reserved.

#include <benchmark/benchmark.h>

#include <flow/core/TypeName.hpp>

static void TypeName_Construct(benchmark::State& state)
{
for ([[maybe_unused]] const auto& _ : state)
{
flow::TypeName<int> name;
benchmark::DoNotOptimize(name);
benchmark::ClobberMemory();
}
}

BENCHMARK(TypeName_Construct);
53 changes: 53 additions & 0 deletions benchmarks/uuid_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2025, Cisco Systems, Inc.
// All rights reserved.

#include <benchmark/benchmark.h>

#include <flow/core/UUID.hpp>

static void UUID_ConstructGenerate(benchmark::State& state)
{
for ([[maybe_unused]] const auto& _ : state)
{
flow::UUID id{};
benchmark::DoNotOptimize(id);
benchmark::ClobberMemory();
}
}

static void UUID_ConstructFromString(benchmark::State& state)
{
for ([[maybe_unused]] const auto& _ : state)
{
flow::UUID id{"b24f917e-3626-4246-bf13-c2543145abfd"};
benchmark::DoNotOptimize(id);
benchmark::ClobberMemory();
}
}

static void UUID_ConstructToString(benchmark::State& state)
{
flow::UUID id{"b24f917e-3626-4246-bf13-c2543145abfd"};
for ([[maybe_unused]] const auto& _ : state)
{
std::string uuid_str = std::string(id);
benchmark::DoNotOptimize(id);
benchmark::ClobberMemory();
}
}

static void UUID_Hash(benchmark::State& state)
{
flow::UUID id{"b24f917e-3626-4246-bf13-c2543145abfd"};
for ([[maybe_unused]] const auto& _ : state)
{
auto h = std::hash<flow::UUID>{}(id);
benchmark::DoNotOptimize(h);
benchmark::ClobberMemory();
}
}

BENCHMARK(UUID_ConstructGenerate);
BENCHMARK(UUID_ConstructFromString);
BENCHMARK(UUID_ConstructToString);
BENCHMARK(UUID_Hash);
9 changes: 0 additions & 9 deletions cabin.toml

This file was deleted.

Loading
Loading