# Benchmark Camera

This example showcases how the
[BenchmarkIn](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/benchmark_in.md) node works. It measures the
FPS and latency of some message stream, in this case, the video stream from the camera.

By default, the node will aggregate 50 messages and then print (firmware warning) the FPS and latency. In our case, that's `33.3ms
(30fps) * 50 messages = 1.665 seconds`.

## Demo

```bash
Benchmark $ python3.9 benchmark_camera.py
[18443010211F850E00] [1.1] [3.367] [BenchmarkIn(1)] [warning] FPS: 30.019516
[18443010211F850E00] [1.1] [3.367] [BenchmarkIn(1)] [warning] Messages took 1.6655831 s
[18443010211F850E00] [1.1] [3.367] [BenchmarkIn(1)] [warning] Average latency: 0.010152339 s
[18443010211F850E00] [1.1] [5.067] [BenchmarkIn(1)] [warning] FPS: 30.000103
[18443010211F850E00] [1.1] [5.067] [BenchmarkIn(1)] [warning] Messages took 1.6666609 s
[18443010211F850E00] [1.1] [5.067] [BenchmarkIn(1)] [warning] Average latency: 0.010102791 s
[18443010211F850E00] [1.1] [6.767] [BenchmarkIn(1)] [warning] FPS: 30.000868
```

This example requires the DepthAI v3 API, see [installation instructions](https://docs.luxonis.com/software-v3/depthai.md).

## Pipeline

## Source code

#### Python

```python
#!/usr/bin/env python3
import depthai as dai
import time

# Create pipeline
with dai.Pipeline() as pipeline:
    # Create the nodes
    cam = pipeline.create(dai.node.Camera).build()
    benchmarkIn = pipeline.create(dai.node.BenchmarkIn)
    # benchmarkIn.setRunOnHost(True) # The node can also run on host and include the transfer limitation, default is False
    output = cam.requestFullResolutionOutput()
    output.link(benchmarkIn.input)

    pipeline.start()
    while pipeline.isRunning():
        time.sleep(1) # Let the logger print out the FPS
```

#### C++

```cpp
#include <atomic>
#include <chrono>
#include <csignal>
#include <depthai/depthai.hpp>
#include <thread>

std::atomic<bool> quitEvent(false);

void signalHandler(int) {
    quitEvent = true;
}

int main() {
    signal(SIGTERM, signalHandler);
    signal(SIGINT, signalHandler);

    // Create pipeline
    dai::Pipeline pipeline;

    // Create the nodes
    auto cam = pipeline.create<dai::node::Camera>()->build();
    auto benchmarkIn = pipeline.create<dai::node::BenchmarkIn>();
    // benchmarkIn->setRunOnHost(true); // The node can also run on host and include the transfer limitation, default is False
    auto* output = cam->requestFullResolutionOutput();
    output->link(benchmarkIn->input);

    pipeline.start();
    while(pipeline.isRunning() && !quitEvent) {
        std::this_thread::sleep_for(std::chrono::seconds(1));  // Let the logger print out the FPS
    }

    pipeline.stop();
    pipeline.wait();

    return 0;
}
```

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
