# log_latency

Python API: `modelconverter.utils.log_latency`

Extraction of inference latency from device logs.

The RVC2 and RVC4 benchmarks measure how long a single inference takes by reading the log messages the device emits through
`depthai`. The two platforms word those messages differently, so a regular expression is provided for each.

## Functions

| Name | Description |
| --- | --- |
| [`parse_inference_latency`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/log_latency.md#log_latency-Functions-parse_inference_latency) | Extract an inference duration in milliseconds from a device log message. |

### function `parse_inference_latency`

```python
def parse_inference_latency(
    log_message: dai.LogMessage,
    pattern: re.Pattern[str],
) -> float | None
```

Extract an inference duration in milliseconds from a device log message.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `log_message` | `dai.LogMessage` | Log message received from the device. | required |
| `pattern` | `re.Pattern[str]` | Regular expression to search the message payload with. Must define a `latency_ms` group. | required |

Returns

| Type | Description |
| --- | --- |
| `float | None` | The latency in milliseconds, or `None` if the payload does not match the pattern. |

## Module Attributes

| Name | Description |
| --- | --- |
| [`RVC2_INFERENCE_LATENCY_RE`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/log_latency.md#log_latency-Module-Attributes-RVC2_INFERENCE_LATENCY_RE) |  |
| [`RVC4_INFERENCE_LATENCY_RE`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/log_latency.md#log_latency-Module-Attributes-RVC4_INFERENCE_LATENCY_RE) |  |

### constant `RVC2_INFERENCE_LATENCY_RE`

```python
RVC2_INFERENCE_LATENCY_RE = re.compile(
    "NeuralNetwork inference took\\s+'(?P<latency_ms>[0-9]+(?:\\.[0-9]+)?)'\\s+ms",
)
```

### constant `RVC4_INFERENCE_LATENCY_RE`

```python
RVC4_INFERENCE_LATENCY_RE = re.compile(
    'Executing the model took:\\s*(?P<latency_ms>[0-9]+(?:\\.[0-9]+)?)\\s*ms',
)
```
