From 68cec9cc283e56776b8d2828f41777a8034fd1d2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Mar 2026 22:32:36 -1000 Subject: [PATCH] Add real Application::loop() benchmark, call original_setup() in main - Call original_setup() in benchmark main.cpp so code-generated App initialization (pre_setup, area/device registration, looping_components_ init) runs before benchmarks - Restore ApplicationLoop_Empty benchmark that calls the actual App.loop() --- tests/benchmarks/components/main.cpp | 4 ++++ .../core/bench_application_loop.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/benchmarks/core/bench_application_loop.cpp diff --git a/tests/benchmarks/components/main.cpp b/tests/benchmarks/components/main.cpp index bae733cbc61..990db92f660 100644 --- a/tests/benchmarks/components/main.cpp +++ b/tests/benchmarks/components/main.cpp @@ -20,6 +20,10 @@ void original_setup() { } void setup() { + // Run auto-generated initialization (App.pre_setup, area/device registration, + // looping_components_.init, etc.) so benchmarks that use App work correctly. + original_setup(); + // Log functions call global_logger->log_vprintf_() without a null check, // so we must set up a Logger before any test that triggers logging. static esphome::logger::Logger test_logger(0); diff --git a/tests/benchmarks/core/bench_application_loop.cpp b/tests/benchmarks/core/bench_application_loop.cpp new file mode 100644 index 00000000000..5acbe8beaad --- /dev/null +++ b/tests/benchmarks/core/bench_application_loop.cpp @@ -0,0 +1,19 @@ +#include + +#include "esphome/core/application.h" + +namespace esphome::benchmarks { + +// Benchmark Application::loop() with no registered components. +// App is initialized by original_setup() in main.cpp (code-generated +// pre_setup, area/device registration, looping_components_.init). +// This measures the baseline overhead of the main loop: scheduler, +// timing, before/after loop tasks, and yield_with_select_. +static void ApplicationLoop_Empty(benchmark::State &state) { + for (auto _ : state) { + App.loop(); + } +} +BENCHMARK(ApplicationLoop_Empty); + +} // namespace esphome::benchmarks