mirror of
https://github.com/esphome/esphome.git
synced 2026-08-30 17:46:01 +00:00
Fix _Fresh benchmark consistency and address review nits
- Remove inner loop from CalcAndEncode_DeviceInfoResponse_Fresh to match SensorStateResponse_Fresh — both now measure single alloc+encode per iteration as intended for heap allocation cost benchmarking - Add comments documenting why _Fresh variants skip inner loops - Add first-wins comment to load_component_yaml_configs - Clean up .gitignore template comment
This commit is contained in:
@@ -70,7 +70,8 @@ static void CalcAndEncode_SensorStateResponse(benchmark::State &state) {
|
||||
}
|
||||
BENCHMARK(CalcAndEncode_SensorStateResponse);
|
||||
|
||||
// Cold path: fresh buffer each iteration (measures heap allocation)
|
||||
// Cold path: fresh buffer each iteration (measures heap allocation).
|
||||
// No inner loop — the point is to measure one alloc+encode per iteration.
|
||||
static void CalcAndEncode_SensorStateResponse_Fresh(benchmark::State &state) {
|
||||
SensorStateResponse msg;
|
||||
msg.key = 0x12345678;
|
||||
@@ -268,21 +269,19 @@ static void CalcAndEncode_DeviceInfoResponse(benchmark::State &state) {
|
||||
}
|
||||
BENCHMARK(CalcAndEncode_DeviceInfoResponse);
|
||||
|
||||
// Cold path: fresh buffer each iteration (measures heap allocation)
|
||||
// Cold path: fresh buffer each iteration (measures heap allocation).
|
||||
// No inner loop — the point is to measure one alloc+encode per iteration.
|
||||
static void CalcAndEncode_DeviceInfoResponse_Fresh(benchmark::State &state) {
|
||||
auto msg = make_device_info_response();
|
||||
|
||||
for (auto _ : state) {
|
||||
for (int i = 0; i < kInnerIterations; i++) {
|
||||
APIBuffer buffer;
|
||||
uint32_t size = msg.calculate_size();
|
||||
buffer.resize(size);
|
||||
ProtoWriteBuffer writer(&buffer, 0);
|
||||
msg.encode(writer);
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
APIBuffer buffer;
|
||||
uint32_t size = msg.calculate_size();
|
||||
buffer.resize(size);
|
||||
ProtoWriteBuffer writer(&buffer, 0);
|
||||
msg.encode(writer);
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
state.SetItemsProcessed(state.iterations() * kInnerIterations);
|
||||
}
|
||||
BENCHMARK(CalcAndEncode_DeviceInfoResponse_Fresh);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user