From 17f2eb19c5a0c15c9f3c45eff54d91bcfe72dab2 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 26 Apr 2026 18:03:10 -0500 Subject: [PATCH] Benchmark trading enginepipeline --- benchmarks/CMakeLists.txt | 4 ++- benchmarks/bench_pipeline.cpp | 54 +++++++++++++++++++++++++++++++++++ tests/test_integration.cpp | 4 ++- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 benchmarks/bench_pipeline.cpp diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index e67624d..9c284e0 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -8,6 +8,7 @@ add_executable(bench_execution_gateway bench_execution_gateway.cpp) add_executable(bench_feed_handler bench_feed_handler.cpp) add_executable(bench_book_snapshot bench_book_snapshot.cpp) add_executable(bench_position_manager bench_position_manager.cpp) +add_executable(bench_pipeline bench_pipeline.cpp) # Link libraries for each foreach(bench_target @@ -19,7 +20,8 @@ foreach(bench_target bench_execution_gateway bench_feed_handler bench_book_snapshot - bench_position_manager) + bench_position_manager + bench_pipeline) target_link_libraries(${bench_target} velox_core benchmark::benchmark diff --git a/benchmarks/bench_pipeline.cpp b/benchmarks/bench_pipeline.cpp new file mode 100644 index 0000000..b2ef4a7 --- /dev/null +++ b/benchmarks/bench_pipeline.cpp @@ -0,0 +1,54 @@ +#include +#include "velox/core/symbol_engine.hpp" +#include "velox/risk/risk_manager.hpp" +#include "velox/gateway/execution_gateway.hpp" +#include "velox/risk/position_manager.hpp" +#include "velox/feed/feed_handler.hpp" +#include "lockfree/pool.hpp" + +using namespace velox; + +static void BM_Pipeline_ProcessFile(benchmark::State& state) { + for (auto _ : state) { + // Fresh components for each iteration + RiskManager risk; + ExecutionGateway gateway; + PositionManager pos_mgr; + FeedHandler feed; + + // Add workers + for (int i = 0; i < 4; ++i) gateway.add_worker(); + + // Create engines for symbols that appear in the file + std::vector> engines; + engines.push_back(std::make_unique("AAPL", &risk, &gateway, &pos_mgr)); + engines.push_back(std::make_unique("MSFT", &risk, &gateway, &pos_mgr)); + engines.push_back(std::make_unique("GOOGL", &risk, &gateway, &pos_mgr)); + + // Route orders from feed to correct engine + feed.on_add_order([&](const Order& order) { + for (auto& e : engines) { + if (strcmp(e->order_book().symbol(), order.symbol) == 0) { + static lockfree::ObjectPool pool; + static std::vector> pending; + auto new_order = pool.acquire(); + *new_order = order; + e->on_market_order(new_order.get()); + pending.push_back(std::move(new_order)); + break; + } + } + }); + + // Process the mock file (or a larger test file) + feed.process_file("test_data/NASDAQ_ITCH50_sample.bin"); + + // Drain engines + for (auto& e : engines) e->run_match_cycle(); + + benchmark::DoNotOptimize(&gateway); + } +} +BENCHMARK(BM_Pipeline_ProcessFile); + +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/tests/test_integration.cpp b/tests/test_integration.cpp index 2783d72..69e3473 100644 --- a/tests/test_integration.cpp +++ b/tests/test_integration.cpp @@ -51,9 +51,11 @@ class IntegrationTest : public ::testing::Test { } void submit_order(Order* order) { + /* std::cout << "[INTEGRATION_TEST] Submitting order ID=" << order->order_id << " symbol=" << order->symbol << std::endl; - + */ + // Find the correct engine for the symbol for (auto& eng : engines) { if (strcmp(eng->order_book().symbol(), order->symbol) == 0) {