The python program processor timeframe?

I would like to add a code snippet, and I would like just CPU runtime (ignoring operating system processes, etc.).

I tried time.clock (), it seems too inaccurate and gives a different answer each time. (In theory, of course, if I run it again for the same piece of code, should it return the same value?)

I played with a timeout for about an hour. In fact, what kills it for me is the installation process, I have to import about 20 functions that are impractical, because I almost simply rewrite my code in the settings section to try to use it.

Cprofiles look more attractive, but do they return CPU time? also, a minor point - it displays too much information. Is there a way to get the output in txt or .dat file so that I can read it?

Greetings

OS: Ubuntu program: python 2.7

+7
source share
2 answers

It sounds like you're looking for a way to execute process time , the best you can do is use timeit.default_timer () , which offers the most accurate function time.clock () or time.time () available on the current platform, but this is a system-wide time which means other processes may interfere with your measurements.

Here is the information from the documents timeit.default_timer ():

, . Windows, time.clock() , time.time() 1/60 . Unix .clock() 1/100- , time.time() - . , default_timer() , . , , , .

c-, .


- time.process_time(), python 3.3 up, :

( ) . , . . undefined, .

+8

time.clock() timeit.default_timer(); . , Ubuntu time.time().

timeit , timeit. , , , , , .

+3

Source: https://habr.com/ru/post/1694698/


All Articles