I understand that time.perf_counter() measures the total time elapsed, even while the process is currently not running. time.process_time() however only measures the time the process is actually running.
If I am just measuring the performance of a function, which of these two is preferred?
Since I am not actually interested in the time my CPU spends tending to other processes, I naturally thought time.process_time() would be the better (and more stable across different runs?) choice, but the name time.perf_counter() seems to suggest otherwise.
Code Example
import time
from tqdm import trange
start_time_proc = time.process_time()
start_time_perf = time.perf_counter()
tmp = False
for _ in trange(10_000_000):
tmp = not tmp
elapsed_time_proc = time.process_time() - start_time_proc
elapsed_time_perf = time.perf_counter() - start_time_perf
print("process_time:", elapsed_time_proc)
print("perf_counter:", elapsed_time_perf)