In general, I use time.time()
to get CPU time for some my codes, for example:
import time
t_start = time.time()
my_code()
t_end = time.time()
cpu_usage_time = t_end - t_start
But actually, I don't know whether the cpu_usage_time
is all used for my code or not, I think the actual time is less than or equal with cpu_usage_time
.
I want to know how to get actual CPU time for my code with Python3.x built-in modules or functions.
Thank you.
you can use time.process_time()
method to get the value of the sum of system and user CPU time of current process.
see https://en.wikipedia.org/wiki/CPU_time and https://docs.python.org/3/library/time.html#time.process_time
hope to help you!