BleBenchmark
Lightweight benchmark utility for measuring BLE operation latency and throughput.
Complements bleStopwatch, LatencyTracker, and ThroughputMeter with single-shot operation benchmarks that capture success/failure status. Works with both real Peripheral instances and FakePeripheral for deterministic testing.
For multi-sample latency statistics, use LatencyTracker. For throughput over multiple operations, use ThroughputMeter.
Usage
val benchmark = BleBenchmark()
val result = benchmark.benchmarkConnection(peripheral)
println("Connected in ${result.elapsed}")Content copied to clipboard
Functions
Link copied to clipboard
suspend fun benchmarkConnection(peripheral: Peripheral, options: ConnectionOptions = ConnectionOptions()): BenchmarkResult
Measure the time to connect to a peripheral.
Link copied to clipboard
suspend fun benchmarkDiscovery(peripheral: Peripheral): Pair<BenchmarkResult, List<DiscoveredService>>
Measure the time to discover services after connection.
Link copied to clipboard
suspend fun benchmarkGattRead(peripheral: Peripheral, characteristic: Characteristic): BenchmarkResult
Measure the round-trip time for a GATT read operation.
Link copied to clipboard
suspend fun benchmarkGattWrite(peripheral: Peripheral, characteristic: Characteristic, data: ByteArray, writeType: WriteType = WriteType.WithResponse): BenchmarkResult
Measure the round-trip time for a GATT write operation.
Link copied to clipboard
Measure L2CAP throughput by writing a payload of dataSize bytes.