mirror of
https://github.com/esphome/esphome.git
synced 2026-09-27 23:10:21 +00:00
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
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#include <benchmark/benchmark.h>
|
|
|
|
#include "esphome/core/helpers.h"
|
|
|
|
namespace esphome::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;
|
|
|
|
// --- random_float() ---
|
|
// Ported from ol.yaml:148 "Random Float Benchmark"
|
|
|
|
static void RandomFloat(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
float result = 0.0f;
|
|
for (int i = 0; i < kInnerIterations; i++) {
|
|
result += random_float();
|
|
}
|
|
benchmark::DoNotOptimize(result);
|
|
}
|
|
state.SetItemsProcessed(state.iterations() * kInnerIterations);
|
|
}
|
|
BENCHMARK(RandomFloat);
|
|
|
|
// --- random_uint32() ---
|
|
|
|
static void RandomUint32(benchmark::State &state) {
|
|
for (auto _ : state) {
|
|
uint32_t result = 0;
|
|
for (int i = 0; i < kInnerIterations; i++) {
|
|
result += random_uint32();
|
|
}
|
|
benchmark::DoNotOptimize(result);
|
|
}
|
|
state.SetItemsProcessed(state.iterations() * kInnerIterations);
|
|
}
|
|
BENCHMARK(RandomUint32);
|
|
|
|
} // namespace esphome::benchmarks
|