# Model computation time measurement when using Torchscript in C++

**URL:** <https://discuss.pytorch.org/t/model-computation-time-measurement-when-using-torchscript-in-c/93218>\
**Category:** C++\
**Created:** [August 18, 2020, 12:27pm UTC](https://discuss.pytorch.org/t/model-computation-time-measurement-when-using-torchscript-in-c/93218 "2020-08-18T12:27:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jungmo\_Ahn](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/j/41988e/32.png) [@Jungmo\_Ahn](https://discuss.pytorch.org/u/Jungmo_Ahn)\
**Post date:** [August 18, 2020, 12:27pm UTC](https://discuss.pytorch.org/t/model-computation-time-measurement-when-using-torchscript-in-c/93218/1 "2020-08-18T12:27:11Z")

</div>

Hello

In order to measure the computation time of the deep learning model when using GPU, we have to keep in mind about GPU operations asynchronicity. Thus, we should use torch.cuda.Event or torch.autograd.profiler in Python.

I found torch::autograd::profiler in libtorch but there is no API documentation to know how to use functions in the library. This looks like C++ version of torch.autograd.profiler which to measure model computation time. However, there are many examples to measure computation time in Python but it is hard to find any example to measure computation time when using GPU in C++.

(This might be because the majority of users except me are familiar to use C++ and C++ library. 😅)

**Could someone provide a simple example to measure computation time of Torchscript model considering both CPU time and GPU time in C++?**

FYI, in order to correctly measure computation time in Python3, please refer this link:  
[https://discuss.pytorch.org/t/how-to-measure-time-in-pytorch/26964](https://discuss.pytorch.org/t/how-to-measure-time-in-pytorch/26964)

Many thanks!

---

<div class="post-metadata">

**Author:** ![glaringlee](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/g/9de053/32.png) [@glaringlee](https://discuss.pytorch.org/u/glaringlee)\
**Post date:** [August 19, 2020, 3:17am UTC](https://discuss.pytorch.org/t/model-computation-time-measurement-when-using-torchscript-in-c/93218/2 "2020-08-19T03:17:01Z")

</div>

@Jungmo_Ahn  
I think you probably should category this as ‘jit’
