# Measure QPU timing in QAOA

**URL:** https://discuss.pennylane.ai/t/measure-qpu-timing-in-qaoa/1783
**Category:** PennyLane Help
**Created:** [April 5, 2022, 2:04pm UTC](https://discuss.pennylane.ai/t/measure-qpu-timing-in-qaoa/1783 "2022-04-05T14:04:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rossp](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@rossp](https://discuss.pennylane.ai/u/rossp)
#### Post date: [April 5, 2022, 2:04pm UTC](https://discuss.pennylane.ai/t/measure-qpu-timing-in-qaoa/1783/1 "2022-04-05T14:04:55Z")

</div>

Hi, I am trying to benchmark a QAOA algorithm and would like to know if there is an example or way on how to measure the actual execution time of the QPU (or the closest way of measuring it in a fair way). This would help me to know the proportion of classical vs. QPU timings for QAOA.

I am using `ExpvalCost` as my cost function, so I would probably need to return the execution time from within this function somehow.

---

<div class="post-metadata">

### Author: ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)
#### Post date: [April 5, 2022, 7:14pm UTC](https://discuss.pennylane.ai/t/measure-qpu-timing-in-qaoa/1783/2 "2022-04-05T19:14:15Z")

</div>

Hi @rossp, welcome to the forum!

I don’t know if any of these options will work for what you need but they are definitely some good starting points:

1. [Here](https://pennylane.ai/qml/demos/adjoint_diff_benchmarking.html) you will find a benchmarking code used on different simulators and with different differentiation methods. If you want to run on hardware you will need to use the parameter-shift differentiation method.
2. [This repo](https://github.com/PennyLaneAI/benchmark) holds some benchmarking tools for PennyLane. Maybe you will find something in there that will be useful for you.
3. Depending on what specific hardware you want to use, there may be hardware-specific functions that will allow you to find the execution time. Here’s an example of how to find the execution time when you’re using an IBM device:

```auto
    import pennylane as qml

    dev = qml.device('qiskit.ibmq', wires=2, backend='ibmq_qasm_simulator')#, ibmqx_token="XXX")
    dev.tracker.active = True
    @qml.qnode(dev)
    def circuit():
        qml.Hadamard(wires = 0)
        return qml.expval(qml.PauliZ(0))
    circuit()
    print(dev.tracker.history)

```

Please let me know if this helps!

---

<div class="post-metadata">

### Author: ![rossp](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@rossp](https://discuss.pennylane.ai/u/rossp)
#### Post date: [April 12, 2022, 8:33am UTC](https://discuss.pennylane.ai/t/measure-qpu-timing-in-qaoa/1783/3 "2022-04-12T08:33:29Z")

</div>

Hi @CatalinaAlbornoz, thanks so much for the reply.  
I have now decided to use a decorator to measure the execution time of execute and batch\_execute of the device class (so `dev.execute(...)` and `dev.batch_execute(...)`. This should be sufficient for the time being.

---

<div class="post-metadata">

### Author: ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)
#### Post date: [April 12, 2022, 6:04pm UTC](https://discuss.pennylane.ai/t/measure-qpu-timing-in-qaoa/1783/4 "2022-04-12T18:04:58Z")

</div>

Hi @rossp, thank you for sharing your solution with us!

Would you like to share the full code you used or contribute it as a feature to PennyLane? This might be very useful for others in the future too.
