Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better monotonic clock for win32 #2178

Closed
totaam opened this issue Feb 26, 2019 · 4 comments
Closed

better monotonic clock for win32 #2178

totaam opened this issue Feb 26, 2019 · 4 comments
Labels

Comments

@totaam
Copy link
Collaborator

totaam commented Feb 26, 2019

Using QueryUnbiasedInterruptTime which requires windows 10, or QueryPerformanceCounter (windows 2000 and later).

@totaam
Copy link
Collaborator Author

totaam commented Jun 20, 2019

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

@totaam
Copy link
Collaborator Author

totaam commented Jun 20, 2019

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.

@totaam totaam closed this as completed Jun 20, 2019
@totaam
Copy link
Collaborator Author

totaam commented Jul 19, 2019

oops (caught by the unit tests): r23233

@totaam totaam added the v2.4.x label Jan 22, 2021
@totaam
Copy link
Collaborator Author

totaam commented Sep 26, 2023

We switched to the standard library in 1f270b9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant