user9371654
user9371654

Reputation: 2408

How to compute the return value of python's "time.process_time()" in milliseconds

I am using python 3.6.5 time.process_time() to compute some performance.

Here its description in its official documentation:

time.process_time() → float

Return the value (in fractional seconds) of the sum of the system and user CPU time of the current process. It does not include time elapsed during sleep. It is process-wide by definition. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.

I used it in a similar way to this small example:

import time
x=0
start = time.process_time()
for x in range(100000):
    performance = time.process_time() - start

print("performance: ",performance)

Which gives me this output based on my machine (so I understand it can be different in another machine):

performance:  0.051401815000000003

1) How can I convert the above value (the output which is supposed to be the elapsed time to perform the loop as an example) to milliseconds? I am confused because the documentation says it returns the value in fractional seconds.

2) What is the meaning of fractional seconds? If it is the fraction on the right of a float of a second, say in 11.56 seconds, it is 0.56, then how can I know the seconds value?

3) I am using it to compute elapsed time or performance time. I just need the time the function took.

I already used it so please try not to suggest another function. Clarify what I used to me please.

Upvotes: 1

Views: 1247

Answers (1)

ForceBru
ForceBru

Reputation: 44926

"in fractional seconds" means "in seconds represented as a floating-point number" (as opposed to C's time, for example, which returns an integral number of seconds).

So, to convert the value to milliseconds, multiply it by 1000.

Upvotes: 4

Related Questions