Best way to measure timing?


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?


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 might be also a good utility to profile your code and fine possible bottlenecks.