#include #include #include #include #include #include #include namespace aethera::mcp::benchmarks { namespace { [[nodiscard]] Plot_Input_Request timestamped_drag_request( Event_Type type = Event_Type::pointer_move) { Plot_Input_Request request; request.plot = "datoviz_point"; request.event.type = type; request.event.time_milliseconds = 1'000.0; request.event.position = {240.0, 180.0}; request.event.global_position = {240.0, 180.0}; request.event.button = Mouse_Button::left; request.event.buttons = 1; return request; } void decode_timestamped_drag(benchmark::State& state) { const auto encoded = encode_protocol_value(timestamped_drag_request()); for ([[maybe_unused]] auto iteration : state) { Plot_Input_Request decoded; decode_protocol_value(decoded, encoded); benchmark::DoNotOptimize(decoded.event.time_milliseconds); benchmark::ClobberMemory(); } state.SetItemsProcessed(state.iterations()); } void decode_timed_render(benchmark::State& state) { const auto encoded = encode_protocol_value( Plot_Render_Request{"datoviz_point", 1'000.0, 720, 420}); for ([[maybe_unused]] auto iteration : state) { Plot_Render_Request decoded; decode_protocol_value(decoded, encoded); benchmark::DoNotOptimize(decoded.time_milliseconds); benchmark::ClobberMemory(); } state.SetItemsProcessed(state.iterations()); } class Control_Path : public benchmark::Fixture { public: void SetUp(const benchmark::State&) override { service = Control_Service::create(); } void TearDown(const benchmark::State&) override { service.reset(); } protected: std::shared_ptr service; }; BENCHMARK_DEFINE_F(Control_Path, Timestamped_Drag_Admission)( benchmark::State& state) { auto request = timestamped_drag_request(Event_Type::pointer_press); auto arguments = encode_protocol_value(request); const auto press = service->call_tool("aethera_plot_input", arguments); if (press.result != Tool_Call_Result::ok) { state.SkipWithError("timestamped pointer press was rejected"); return; } arguments["event"]["type"] = "pointer_move"; double time_milliseconds = request.event.time_milliseconds; for ([[maybe_unused]] auto iteration : state) { time_milliseconds += 1'000.0 / 120.0; arguments["event"]["time_milliseconds"] = time_milliseconds; const auto result = service->call_tool( "aethera_plot_input", arguments); if (result.result != Tool_Call_Result::ok) { state.SkipWithError("timestamped pointer move was rejected"); break; } benchmark::DoNotOptimize(result.result); } state.SetItemsProcessed(state.iterations()); } BENCHMARK(decode_timestamped_drag); BENCHMARK(decode_timed_render); BENCHMARK_REGISTER_F(Control_Path, Timestamped_Drag_Admission) ->Iterations(512); } } int main(int argc, char** argv) { aethera::initialize_runtime({}); benchmark::Initialize(&argc, argv); if (benchmark::ReportUnrecognizedArguments(argc, argv)) return 2; benchmark::RunSpecifiedBenchmarks(); benchmark::Shutdown(); return 0; }