From 9c148da76adb8189605ab3860782563b5c8ee3f8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Mar 2026 20:49:48 -1000 Subject: [PATCH] Add core benchmarks dir, fix core pseudo-component, use simulation mode - Move scheduler/loop/helpers benchmarks to tests/benchmarks/components/core/ - Add random_float and random_uint32 benchmarks (from ol.yaml) - Fix core pseudo-component crash: skip components where get_component() returns None when adding dependencies to config - Use CodSpeed simulation mode (CPU instruction counting) for reproducible CI results instead of walltime --- .github/workflows/ci.yml | 1 + script/test_helpers.py | 4 ++- .../{api => core}/bench_application_loop.cpp | 0 .../components/core/bench_helpers.cpp | 26 +++++++++++++++++++ .../{api => core}/bench_scheduler.cpp | 0 5 files changed, 30 insertions(+), 1 deletion(-) rename tests/benchmarks/components/{api => core}/bench_application_loop.cpp (100%) create mode 100644 tests/benchmarks/components/core/bench_helpers.cpp rename tests/benchmarks/components/{api => core}/bench_scheduler.cpp (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72c3762189d..a6b9f3580d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -339,6 +339,7 @@ jobs: with: run: ${{ steps.build.outputs.binary }} token: ${{ secrets.CODSPEED_TOKEN }} + mode: simulation clang-tidy-single: name: ${{ matrix.name }} diff --git a/script/test_helpers.py b/script/test_helpers.py index 1941168dafa..3a7e23c0a78 100644 --- a/script/test_helpers.py +++ b/script/test_helpers.py @@ -248,7 +248,9 @@ def compile_and_get_binary( domain_list = config.setdefault(domain, []) CORE.testing_ensure_platform_registered(domain) domain_list.append({CONF_PLATFORM: component}) - else: + # Skip "core" — it's a pseudo-component handled by the build + # system, not a real loadable component (get_component returns None) + elif get_component(component_name) is not None: config.setdefault(component_name, []) # Register platforms from the extra config (benchmark.yaml) so diff --git a/tests/benchmarks/components/api/bench_application_loop.cpp b/tests/benchmarks/components/core/bench_application_loop.cpp similarity index 100% rename from tests/benchmarks/components/api/bench_application_loop.cpp rename to tests/benchmarks/components/core/bench_application_loop.cpp diff --git a/tests/benchmarks/components/core/bench_helpers.cpp b/tests/benchmarks/components/core/bench_helpers.cpp new file mode 100644 index 00000000000..15e0bc5ab1a --- /dev/null +++ b/tests/benchmarks/components/core/bench_helpers.cpp @@ -0,0 +1,26 @@ +#include + +#include "esphome/core/helpers.h" + +namespace esphome::benchmarks { + +// --- random_float() --- +// Ported from ol.yaml:148 "Random Float Benchmark" + +static void BM_RandomFloat(benchmark::State &state) { + for (auto _ : state) { + benchmark::DoNotOptimize(random_float()); + } +} +BENCHMARK(BM_RandomFloat); + +// --- random_uint32() --- + +static void BM_RandomUint32(benchmark::State &state) { + for (auto _ : state) { + benchmark::DoNotOptimize(random_uint32()); + } +} +BENCHMARK(BM_RandomUint32); + +} // namespace esphome::benchmarks diff --git a/tests/benchmarks/components/api/bench_scheduler.cpp b/tests/benchmarks/components/core/bench_scheduler.cpp similarity index 100% rename from tests/benchmarks/components/api/bench_scheduler.cpp rename to tests/benchmarks/components/core/bench_scheduler.cpp