mirror of
https://github.com/esphome/esphome.git
synced 2026-10-06 10:56:43 +00:00
Add inner iteration loops to amortize CodSpeed instrumentation overhead
Sub-microsecond benchmarks are dominated by the ~60ns per-iteration valgrind start/stop cost in CodSpeed simulation mode. Add kInnerIterations (1000) inner loops to all fast benchmarks so the actual work dominates. Move DoNotOptimize calls outside inner loops to prevent artificial overhead. Also address review feedback: - Use tokenless CodSpeed (public repo, no CODSPEED_TOKEN needed) - Fix warning message to show component-specific path - Fix stray ". :" in error message - Verify pinned SHA on re-runs to prevent stale checkouts
This commit is contained in:
@@ -5,6 +5,11 @@
|
||||
|
||||
namespace esphome::api::benchmarks {
|
||||
|
||||
// Inner iteration count to amortize CodSpeed instrumentation overhead.
|
||||
// Without this, the ~60ns per-iteration valgrind start/stop cost dominates
|
||||
// sub-microsecond benchmarks.
|
||||
static constexpr int kInnerIterations = 1000;
|
||||
|
||||
// --- HelloRequest decode (string + varint fields) ---
|
||||
|
||||
static void Decode_HelloRequest(benchmark::State &state) {
|
||||
@@ -21,9 +26,12 @@ static void Decode_HelloRequest(benchmark::State &state) {
|
||||
|
||||
for (auto _ : state) {
|
||||
HelloRequest msg;
|
||||
msg.decode(encoded, sizeof(encoded));
|
||||
for (int i = 0; i < kInnerIterations; i++) {
|
||||
msg.decode(encoded, sizeof(encoded));
|
||||
}
|
||||
benchmark::DoNotOptimize(msg.api_version_major);
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations() * kInnerIterations);
|
||||
}
|
||||
BENCHMARK(Decode_HelloRequest);
|
||||
|
||||
@@ -39,9 +47,12 @@ static void Decode_SwitchCommandRequest(benchmark::State &state) {
|
||||
|
||||
for (auto _ : state) {
|
||||
SwitchCommandRequest msg;
|
||||
msg.decode(encoded, sizeof(encoded));
|
||||
for (int i = 0; i < kInnerIterations; i++) {
|
||||
msg.decode(encoded, sizeof(encoded));
|
||||
}
|
||||
benchmark::DoNotOptimize(msg.state);
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations() * kInnerIterations);
|
||||
}
|
||||
BENCHMARK(Decode_SwitchCommandRequest);
|
||||
|
||||
@@ -110,9 +121,12 @@ static void Decode_LightCommandRequest(benchmark::State &state) {
|
||||
|
||||
for (auto _ : state) {
|
||||
LightCommandRequest msg;
|
||||
msg.decode(encoded, sizeof(encoded));
|
||||
for (int i = 0; i < kInnerIterations; i++) {
|
||||
msg.decode(encoded, sizeof(encoded));
|
||||
}
|
||||
benchmark::DoNotOptimize(msg.brightness);
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations() * kInnerIterations);
|
||||
}
|
||||
BENCHMARK(Decode_LightCommandRequest);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user