BleBenchmark

class BleBenchmark(timeSource: TimeSource = TimeSource.Monotonic)

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}")

Constructors

Link copied to clipboard
constructor(timeSource: TimeSource = TimeSource.Monotonic)

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
suspend fun benchmarkThroughput(channel: L2capChannel, dataSize: Int = 65536): ThroughputResult

Measure L2CAP throughput by writing a payload of dataSize bytes.