From ed539e17ff3ce8221d82a1c7290a90bc349dfd99 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Mar 2026 23:57:39 -1000 Subject: [PATCH] Add scheduler benchmark with 5 intervals firing per call Adds Scheduler_Call_5IntervalsFiring: 5 intervals with 1ms period, time advancing each inner iteration so all 5 fire every call(). This benchmarks the real scheduler hot path where callbacks execute. --- tests/benchmarks/core/bench_scheduler.cpp | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/benchmarks/core/bench_scheduler.cpp b/tests/benchmarks/core/bench_scheduler.cpp index d9d1575ebd..babcfc0be3 100644 --- a/tests/benchmarks/core/bench_scheduler.cpp +++ b/tests/benchmarks/core/bench_scheduler.cpp @@ -50,6 +50,34 @@ static void Scheduler_Call_TimersNotDue(benchmark::State &state) { } BENCHMARK(Scheduler_Call_TimersNotDue); +// --- Scheduler with 5 intervals firing every call --- + +static void Scheduler_Call_5IntervalsFiring(benchmark::State &state) { + Scheduler scheduler; + Component dummy_component; + int fire_count = 0; + + // Add 5 intervals with 1ms period — they fire every call when time advances + for (int i = 0; i < 5; i++) { + scheduler.set_interval(&dummy_component, static_cast(i), 1, [&fire_count]() { fire_count++; }); + } + scheduler.process_to_add(); + + // Start at a known time so intervals are immediately due + uint32_t now = millis() + 100; + + for (auto _ : state) { + for (int i = 0; i < kInnerIterations; i++) { + scheduler.call(now); + // Advance time by 1ms so intervals are due again next call + now++; + } + benchmark::DoNotOptimize(fire_count); + } + state.SetItemsProcessed(state.iterations() * kInnerIterations); +} +BENCHMARK(Scheduler_Call_5IntervalsFiring); + // --- Scheduler: next_schedule_in() calculation --- static void Scheduler_NextScheduleIn(benchmark::State &state) {