mirror of
https://github.com/esphome/esphome.git
synced 2026-09-14 00:28:39 +00:00
Remove BM_ prefix, drop application loop benchmark, fix core includes
- Remove BM_ prefix from all benchmark names (unnecessary convention) - Remove bench_application_loop.cpp (App needs pre_setup/setup which requires full code generation; will revisit as integration benchmark) - Fix extra_include_dirs to use os.path.relpath for sibling directories
This commit is contained in:
@@ -356,13 +356,9 @@ def build_and_run(
|
||||
if extra_include_dirs:
|
||||
for d in extra_include_dirs:
|
||||
if d.is_dir() and (any(d.glob("*.cpp")) or any(d.glob("*.h"))):
|
||||
# Use path relative to tests_dir for PlatformIO includes
|
||||
try:
|
||||
rel = d.relative_to(tests_dir)
|
||||
includes.append(str(rel))
|
||||
except ValueError:
|
||||
# Not relative to tests_dir, use absolute
|
||||
includes.append(str(d))
|
||||
# ESPHome includes are relative to the config directory (tests_dir)
|
||||
rel = os.path.relpath(d, tests_dir)
|
||||
includes.append(rel)
|
||||
|
||||
# Discover platform sub-components
|
||||
try:
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace esphome::api::benchmarks {
|
||||
|
||||
// --- HelloRequest decode (string + varint fields) ---
|
||||
|
||||
static void BM_Decode_HelloRequest(benchmark::State &state) {
|
||||
static void Decode_HelloRequest(benchmark::State &state) {
|
||||
// Manually encoded HelloRequest:
|
||||
// field 1 (string): "aioesphomeapi"
|
||||
// field 2 (varint): 1 (api_version_major)
|
||||
@@ -25,11 +25,11 @@ static void BM_Decode_HelloRequest(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(msg.api_version_major);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Decode_HelloRequest);
|
||||
BENCHMARK(Decode_HelloRequest);
|
||||
|
||||
// --- SwitchCommandRequest decode (simple command) ---
|
||||
|
||||
static void BM_Decode_SwitchCommandRequest(benchmark::State &state) {
|
||||
static void Decode_SwitchCommandRequest(benchmark::State &state) {
|
||||
// field 1 (fixed32): key = 0x12345678
|
||||
// field 2 (varint): state = true
|
||||
uint8_t encoded[] = {
|
||||
@@ -43,11 +43,11 @@ static void BM_Decode_SwitchCommandRequest(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(msg.state);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Decode_SwitchCommandRequest);
|
||||
BENCHMARK(Decode_SwitchCommandRequest);
|
||||
|
||||
// --- LightCommandRequest decode (complex command with many fields) ---
|
||||
|
||||
static void BM_Decode_LightCommandRequest(benchmark::State &state) {
|
||||
static void Decode_LightCommandRequest(benchmark::State &state) {
|
||||
uint8_t encoded[] = {
|
||||
// field 1: key (fixed32) = 0x11223344
|
||||
0x0D,
|
||||
@@ -114,6 +114,6 @@ static void BM_Decode_LightCommandRequest(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(msg.brightness);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Decode_LightCommandRequest);
|
||||
BENCHMARK(Decode_LightCommandRequest);
|
||||
|
||||
} // namespace esphome::api::benchmarks
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace esphome::api::benchmarks {
|
||||
|
||||
// --- SensorStateResponse (highest frequency message) ---
|
||||
|
||||
static void BM_Encode_SensorStateResponse(benchmark::State &state) {
|
||||
static void Encode_SensorStateResponse(benchmark::State &state) {
|
||||
APIBuffer buffer;
|
||||
SensorStateResponse msg;
|
||||
msg.key = 0x12345678;
|
||||
@@ -22,9 +22,9 @@ static void BM_Encode_SensorStateResponse(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Encode_SensorStateResponse);
|
||||
BENCHMARK(Encode_SensorStateResponse);
|
||||
|
||||
static void BM_CalculateSize_SensorStateResponse(benchmark::State &state) {
|
||||
static void CalculateSize_SensorStateResponse(benchmark::State &state) {
|
||||
SensorStateResponse msg;
|
||||
msg.key = 0x12345678;
|
||||
msg.state = 23.5f;
|
||||
@@ -34,9 +34,9 @@ static void BM_CalculateSize_SensorStateResponse(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(msg.calculate_size());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_CalculateSize_SensorStateResponse);
|
||||
BENCHMARK(CalculateSize_SensorStateResponse);
|
||||
|
||||
static void BM_CalcAndEncode_SensorStateResponse(benchmark::State &state) {
|
||||
static void CalcAndEncode_SensorStateResponse(benchmark::State &state) {
|
||||
APIBuffer buffer;
|
||||
SensorStateResponse msg;
|
||||
msg.key = 0x12345678;
|
||||
@@ -51,11 +51,11 @@ static void BM_CalcAndEncode_SensorStateResponse(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_CalcAndEncode_SensorStateResponse);
|
||||
BENCHMARK(CalcAndEncode_SensorStateResponse);
|
||||
|
||||
// --- BinarySensorStateResponse ---
|
||||
|
||||
static void BM_Encode_BinarySensorStateResponse(benchmark::State &state) {
|
||||
static void Encode_BinarySensorStateResponse(benchmark::State &state) {
|
||||
APIBuffer buffer;
|
||||
BinarySensorStateResponse msg;
|
||||
msg.key = 0xAABBCCDD;
|
||||
@@ -70,11 +70,11 @@ static void BM_Encode_BinarySensorStateResponse(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Encode_BinarySensorStateResponse);
|
||||
BENCHMARK(Encode_BinarySensorStateResponse);
|
||||
|
||||
// --- HelloResponse (string fields) ---
|
||||
|
||||
static void BM_Encode_HelloResponse(benchmark::State &state) {
|
||||
static void Encode_HelloResponse(benchmark::State &state) {
|
||||
APIBuffer buffer;
|
||||
HelloResponse msg;
|
||||
msg.api_version_major = 1;
|
||||
@@ -90,11 +90,11 @@ static void BM_Encode_HelloResponse(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Encode_HelloResponse);
|
||||
BENCHMARK(Encode_HelloResponse);
|
||||
|
||||
// --- LightStateResponse (complex multi-field message) ---
|
||||
|
||||
static void BM_Encode_LightStateResponse(benchmark::State &state) {
|
||||
static void Encode_LightStateResponse(benchmark::State &state) {
|
||||
APIBuffer buffer;
|
||||
LightStateResponse msg;
|
||||
msg.key = 0x11223344;
|
||||
@@ -119,9 +119,9 @@ static void BM_Encode_LightStateResponse(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Encode_LightStateResponse);
|
||||
BENCHMARK(Encode_LightStateResponse);
|
||||
|
||||
static void BM_CalculateSize_LightStateResponse(benchmark::State &state) {
|
||||
static void CalculateSize_LightStateResponse(benchmark::State &state) {
|
||||
LightStateResponse msg;
|
||||
msg.key = 0x11223344;
|
||||
msg.state = true;
|
||||
@@ -141,7 +141,7 @@ static void BM_CalculateSize_LightStateResponse(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(msg.calculate_size());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_CalculateSize_LightStateResponse);
|
||||
BENCHMARK(CalculateSize_LightStateResponse);
|
||||
|
||||
// --- DeviceInfoResponse (nested submessages: 20 devices + 20 areas) ---
|
||||
|
||||
@@ -170,16 +170,16 @@ static DeviceInfoResponse make_device_info_response() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
static void BM_CalculateSize_DeviceInfoResponse(benchmark::State &state) {
|
||||
static void CalculateSize_DeviceInfoResponse(benchmark::State &state) {
|
||||
auto msg = make_device_info_response();
|
||||
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(msg.calculate_size());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_CalculateSize_DeviceInfoResponse);
|
||||
BENCHMARK(CalculateSize_DeviceInfoResponse);
|
||||
|
||||
static void BM_Encode_DeviceInfoResponse(benchmark::State &state) {
|
||||
static void Encode_DeviceInfoResponse(benchmark::State &state) {
|
||||
auto msg = make_device_info_response();
|
||||
APIBuffer buffer;
|
||||
uint32_t total_size = msg.calculate_size();
|
||||
@@ -191,9 +191,9 @@ static void BM_Encode_DeviceInfoResponse(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Encode_DeviceInfoResponse);
|
||||
BENCHMARK(Encode_DeviceInfoResponse);
|
||||
|
||||
static void BM_CalcAndEncode_DeviceInfoResponse(benchmark::State &state) {
|
||||
static void CalcAndEncode_DeviceInfoResponse(benchmark::State &state) {
|
||||
auto msg = make_device_info_response();
|
||||
APIBuffer buffer;
|
||||
|
||||
@@ -205,6 +205,6 @@ static void BM_CalcAndEncode_DeviceInfoResponse(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_CalcAndEncode_DeviceInfoResponse);
|
||||
BENCHMARK(CalcAndEncode_DeviceInfoResponse);
|
||||
|
||||
} // namespace esphome::api::benchmarks
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace esphome::api::benchmarks {
|
||||
|
||||
// --- ProtoVarInt::parse() benchmarks ---
|
||||
|
||||
static void BM_ProtoVarInt_Parse_SingleByte(benchmark::State &state) {
|
||||
static void ProtoVarInt_Parse_SingleByte(benchmark::State &state) {
|
||||
// Single-byte varint (0-127) — the most common case (fast path)
|
||||
uint8_t buf[] = {0x42}; // value = 66
|
||||
|
||||
@@ -16,9 +16,9 @@ static void BM_ProtoVarInt_Parse_SingleByte(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(result);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_ProtoVarInt_Parse_SingleByte);
|
||||
BENCHMARK(ProtoVarInt_Parse_SingleByte);
|
||||
|
||||
static void BM_ProtoVarInt_Parse_TwoByte(benchmark::State &state) {
|
||||
static void ProtoVarInt_Parse_TwoByte(benchmark::State &state) {
|
||||
// Two-byte varint (128-16383)
|
||||
uint8_t buf[] = {0x80, 0x01}; // value = 128
|
||||
|
||||
@@ -27,9 +27,9 @@ static void BM_ProtoVarInt_Parse_TwoByte(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(result);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_ProtoVarInt_Parse_TwoByte);
|
||||
BENCHMARK(ProtoVarInt_Parse_TwoByte);
|
||||
|
||||
static void BM_ProtoVarInt_Parse_FiveByte(benchmark::State &state) {
|
||||
static void ProtoVarInt_Parse_FiveByte(benchmark::State &state) {
|
||||
// Five-byte varint (max uint32 = 4294967295)
|
||||
uint8_t buf[] = {0xFF, 0xFF, 0xFF, 0xFF, 0x0F};
|
||||
|
||||
@@ -38,11 +38,11 @@ static void BM_ProtoVarInt_Parse_FiveByte(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(result);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_ProtoVarInt_Parse_FiveByte);
|
||||
BENCHMARK(ProtoVarInt_Parse_FiveByte);
|
||||
|
||||
// --- Varint encoding benchmarks ---
|
||||
|
||||
static void BM_Encode_Varint_Small(benchmark::State &state) {
|
||||
static void Encode_Varint_Small(benchmark::State &state) {
|
||||
// Value < 128 — single byte fast path
|
||||
APIBuffer buffer;
|
||||
buffer.resize(16);
|
||||
@@ -53,9 +53,9 @@ static void BM_Encode_Varint_Small(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Encode_Varint_Small);
|
||||
BENCHMARK(Encode_Varint_Small);
|
||||
|
||||
static void BM_Encode_Varint_Large(benchmark::State &state) {
|
||||
static void Encode_Varint_Large(benchmark::State &state) {
|
||||
// Value > 128 — multi-byte slow path
|
||||
APIBuffer buffer;
|
||||
buffer.resize(16);
|
||||
@@ -66,9 +66,9 @@ static void BM_Encode_Varint_Large(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Encode_Varint_Large);
|
||||
BENCHMARK(Encode_Varint_Large);
|
||||
|
||||
static void BM_Encode_Varint_MaxUint32(benchmark::State &state) {
|
||||
static void Encode_Varint_MaxUint32(benchmark::State &state) {
|
||||
APIBuffer buffer;
|
||||
buffer.resize(16);
|
||||
|
||||
@@ -78,22 +78,22 @@ static void BM_Encode_Varint_MaxUint32(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(buffer.data());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Encode_Varint_MaxUint32);
|
||||
BENCHMARK(Encode_Varint_MaxUint32);
|
||||
|
||||
// --- ProtoSize::varint() benchmarks ---
|
||||
|
||||
static void BM_ProtoSize_Varint_Small(benchmark::State &state) {
|
||||
static void ProtoSize_Varint_Small(benchmark::State &state) {
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(ProtoSize::varint(42));
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_ProtoSize_Varint_Small);
|
||||
BENCHMARK(ProtoSize_Varint_Small);
|
||||
|
||||
static void BM_ProtoSize_Varint_Large(benchmark::State &state) {
|
||||
static void ProtoSize_Varint_Large(benchmark::State &state) {
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(ProtoSize::varint(0xFFFFFFFF));
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_ProtoSize_Varint_Large);
|
||||
BENCHMARK(ProtoSize_Varint_Large);
|
||||
|
||||
} // namespace esphome::api::benchmarks
|
||||
|
||||
@@ -7,20 +7,20 @@ namespace esphome::benchmarks {
|
||||
// --- random_float() ---
|
||||
// Ported from ol.yaml:148 "Random Float Benchmark"
|
||||
|
||||
static void BM_RandomFloat(benchmark::State &state) {
|
||||
static void RandomFloat(benchmark::State &state) {
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(random_float());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_RandomFloat);
|
||||
BENCHMARK(RandomFloat);
|
||||
|
||||
// --- random_uint32() ---
|
||||
|
||||
static void BM_RandomUint32(benchmark::State &state) {
|
||||
static void RandomUint32(benchmark::State &state) {
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(random_uint32());
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_RandomUint32);
|
||||
BENCHMARK(RandomUint32);
|
||||
|
||||
} // namespace esphome::benchmarks
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace esphome::benchmarks {
|
||||
|
||||
// --- Scheduler fast path: no work to do ---
|
||||
|
||||
static void BM_Scheduler_Call_NoWork(benchmark::State &state) {
|
||||
static void Scheduler_Call_NoWork(benchmark::State &state) {
|
||||
Scheduler scheduler;
|
||||
uint32_t now = millis();
|
||||
|
||||
@@ -16,11 +16,11 @@ static void BM_Scheduler_Call_NoWork(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(now);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Scheduler_Call_NoWork);
|
||||
BENCHMARK(Scheduler_Call_NoWork);
|
||||
|
||||
// --- Scheduler with timers: call() when timers exist but aren't due ---
|
||||
|
||||
static void BM_Scheduler_Call_TimersNotDue(benchmark::State &state) {
|
||||
static void Scheduler_Call_TimersNotDue(benchmark::State &state) {
|
||||
Scheduler scheduler;
|
||||
Component dummy_component;
|
||||
|
||||
@@ -37,11 +37,11 @@ static void BM_Scheduler_Call_TimersNotDue(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(now);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Scheduler_Call_TimersNotDue);
|
||||
BENCHMARK(Scheduler_Call_TimersNotDue);
|
||||
|
||||
// --- Scheduler: next_schedule_in() calculation ---
|
||||
|
||||
static void BM_Scheduler_NextScheduleIn(benchmark::State &state) {
|
||||
static void Scheduler_NextScheduleIn(benchmark::State &state) {
|
||||
Scheduler scheduler;
|
||||
Component dummy_component;
|
||||
|
||||
@@ -58,6 +58,6 @@ static void BM_Scheduler_NextScheduleIn(benchmark::State &state) {
|
||||
benchmark::DoNotOptimize(result);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_Scheduler_NextScheduleIn);
|
||||
BENCHMARK(Scheduler_NextScheduleIn);
|
||||
|
||||
} // namespace esphome::benchmarks
|
||||
|
||||
Reference in New Issue
Block a user