# BenchmarkIn

BenchmarkIn 节点设计用于接收消息并测量传入流的帧率（FPS）和延迟。它会定期生成性能报告，从而有助于对您的 DepthAI 流水线进行基准测试和性能分析。

## 如何放置

#### Python

```python
import depthai as dai

pipeline = dai.Pipeline()
benchmarkIn = pipeline.create(dai.node.BenchmarkIn)

# 配置为每100条消息发送一次性能报告，并选择是否将报告作为警告记录。
benchmarkIn.sendReportEveryNMessages(100)
benchmarkIn.logReportsAsWarnings(False)

# 例如，将 NeuralNetwork 的输出连接到 BenchmarkIn：
neuralNetwork = pipeline.create(dai.node.NeuralNetwork)
neuralNetwork.out.link(benchmarkIn.input)
```

#### C++

```cpp
#include "depthai/depthai.hpp"

dai::Pipeline pipeline;
auto benchmarkIn = pipeline.create<dai::node::BenchmarkIn>();

// 配置 BenchmarkIn 每100条消息发送一次报告，并决定是否将报告作为警告记录。
benchmarkIn->sendReportEveryNMessages(100);
benchmarkIn->logReportsAsWarnings(false);

// 例如，将 NeuralNetwork 的输出连接到 BenchmarkIn：
auto neuralNetwork = pipeline.create<dai::node::NeuralNetwork>();
neuralNetwork->out.link(benchmarkIn->input);
```

## 输入和输出

## 使用方法

BenchmarkIn 通常连接到另一个节点（例如，神经网络或相机节点）的输出，以便监控数据流的性能。该节点周期性地发出包含性能指标（如FPS和延迟）的 BenchmarkReport。

#### Python

```python
pipeline = dai.Pipeline()

# 创建 BenchmarkIn 节点并进行配置：
benchmarkIn = pipeline.create(dai.node.BenchmarkIn)
benchmarkIn.sendReportEveryNMessages(100)
benchmarkIn.logReportsAsWarnings(False)

# 示例：将 BenchmarkIn 连接到 NeuralNetwork 节点
neuralNetwork = pipeline.create(dai.node.NeuralNetwork)
neuralNetwork.out.link(benchmarkIn.input)

# 创建用于接收基准测试报告的输出队列
outputQueue = benchmarkIn.report.createOutputQueue()

while pipeline.isRunning():
    benchmarkReport = outputQueue.get()
    print(f"FPS 是 {benchmarkReport.fps}")
```

#### C++

```cpp
dai::Pipeline pipeline;
auto benchmarkIn = pipeline.create<dai::node::BenchmarkIn>();
benchmarkIn->sendReportEveryNMessages(100);
benchmarkIn->logReportsAsWarnings(false);

auto neuralNetwork = pipeline.create<dai::node::NeuralNetwork>();
neuralNetwork->out.link(benchmarkIn->input);

auto outputQueue = benchmarkIn->report.createOutputQueue();
while(pipeline.isRunning()) {
    auto benchmarkReport = outputQueue->get<dai::BenchmarkReport>();
    std::cout << "FPS 是 " << benchmarkReport.fps << std::endl;
}
```

## 功能示例

 * [相机基准测试](https://docs.luxonis.com/software-v3/depthai/examples/benchmark/benchmark_camera.md)
 * [神经网络基准测试](https://docs.luxonis.com/software-v3/depthai/examples/benchmark/benchmark_nn.md)
 * [简单基准测试](https://docs.luxonis.com/software-v3/depthai/examples/benchmark/benchmark_simple.md)

## 参考

### dai::node::BenchmarkIn

Kind: class

#### Input input

Kind: variable

Receive messages as fast as possible

#### Output passthrough

Kind: variable

Passthrough for input messages (so the node can be placed between other nodes)

#### Output report

Kind: variable

Send a benchmark report when the set number of messages are received

#### void sendReportEveryNMessages(uint32_t n)

Kind: function

Specify how many messages to measure for each report

#### void setRunOnHost(bool runOnHost)

Kind: function

Specify whether to run on host or device By default, the node will run on device.

#### bool runOnHost()

Kind: function

Check if the node is set to run on host

#### void logReportsAsWarnings(bool logReportsAsWarnings)

Kind: function

Log the reports as warnings

#### void measureIndividualLatencies(bool attachLatencies)

Kind: function

Attach latencies to the report

#### void run()

Kind: function

#### DeviceNodeCRTP()

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Kind: function

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
