Using QueryPerformanceCounter (windows 2000 and later).
Interesting results:
$ python3 -m timeit "from xpra.os_util import monotonic_time;monotonic_time()" 500000 loops, best of 5: 650 nsec per loop $ python3 -m timeit "from xpra.os_util import time;time.perf_counter()" 200000 loops, best of 5: 1.1 usec per loop $ python3 -m timeit "from xpra.os_util import time;time.clock()" C:/msys64/mingw64/lib/python3.7\timeit.py:6: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead times. See also Tim Peters' introduction to the Algorithms chapter in 200000 loops, best of 5: 1.76 usec per loop
python2 doesn't have time.perf_counter
, here's the data:
$ PYTHONPATH=../build/exe.mingw-2.7/lib python2 -m timeit "from xpra.os_util import monotonic_time;monotonic_time()" 1000000 loops, best of 3: 0.577 usec per loop $ python2 -m timeit "from time import clock;clock()" 1000000 loops, best of 3: 0.84 usec per loop
r23001 adds a QueryPerformanceCounter
implementation.
New data:
$ PYTHONPATH=../build/exe.mingw-2.7/lib python2 -m timeit "from xpra.os_util import monotonic_time;monotonic_time()" 1000000 loops, best of 3: 0.563 usec per loop $ PYTHONPATH=../build/exe.mingw-3.7/lib python3 -m timeit "from xpra.os_util import monotonic_time;monotonic_time()" 200000 loops, best of 5: 1.06 usec per loop
So we lost a tiny bit of performance with python3 (not with python2), but we gained precision.
The python2 time.clock uses QueryPerformanceCounter
, but it is deprecated in python3.
oops (caught by the unit tests): r23233
this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/2178