# Best way to measure timing?

**URL:** <https://discuss.pytorch.org/t/best-way-to-measure-timing/39496>\
**Category:** Uncategorized\
**Created:** [March 11, 2019, 2:57pm UTC](https://discuss.pytorch.org/t/best-way-to-measure-timing/39496 "2019-03-11T14:57:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jGsch](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jgsch/32/4230_2.png) [@jGsch](https://discuss.pytorch.org/u/jGsch)\
**Post date:** [March 11, 2019, 2:57pm UTC](https://discuss.pytorch.org/t/best-way-to-measure-timing/39496/1 "2019-03-11T14:57:14Z")

</div>

Hello,

I’m looking for the best way to measure the timing of a process: `time.perf_counter` or `time.process_time`?

I have seen in several topics that people use more `perf_counter` but `process_time` is process-wide (1).

But in the docs, you can see that process\_time “Return the value (in fractional seconds) of the sum of the system and user CPU time of the current process.”. Does this function still consider GPU computing?

(1) [https://docs.python.org/3/library/time.html#time.process\_time](https://docs.python.org/3/library/time.html#time.process_time)

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [March 11, 2019, 2:59pm UTC](https://discuss.pytorch.org/t/best-way-to-measure-timing/39496/2 "2019-03-11T14:59:23Z")

</div>

`time.perf_counter()` might be a good first approach to time your code.  
Note that CUDA calls are asynchronous, so that you would have to synchronize your code before starting and stopping the timer using `torch.cuda.synchronize()`.  
[torch.utils.bottleneck](https://pytorch.org/docs/stable/bottleneck.html) might be also a good utility to profile your code and fine possible bottlenecks.
