Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High-precision system time in python

Is there any way of obtaining high-precision system time in python?

I have a little application to work with virtual COM-port. I want to measure the time interval between the sending of the message and its receiving.

At the moment it works like this:

I obtain the message, use

    time.time()

and append its 20 digits to the message. The client application receives this message and gets

    time.time()

again, then calculates their differences. At the most of the cases the time interval (as i expected) equals zero.

The question is: is there any way of doing this in more intelligent way and with more precision?

like image 454
mr_borsch Avatar asked Nov 04 '22 10:11

mr_borsch


1 Answers

Here is an excerpt from time.clock

On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the same name, but in any case, this is the function to use for benchmarking Python or timing algorithms.

On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond.

(emphasis mine)

like image 96
Brigand Avatar answered Nov 15 '22 13:11

Brigand