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

Use time.perf_counter_ns() instead of time.time_ns() #4

Open
sueskind opened this issue Oct 9, 2023 · 0 comments
Open

Use time.perf_counter_ns() instead of time.time_ns() #4

sueskind opened this issue Oct 9, 2023 · 0 comments

Comments

@sueskind
Copy link

sueskind commented Oct 9, 2023

First, thank you for this great project!

However, I fear, that there is some issue with the time measurement. Using time.get_clock_info() we can get this information:

>>> time.get_clock_info("time")
namespace(implementation='clock_gettime(CLOCK_REALTIME)', monotonic=False, adjustable=True, resolution=1e-09)
>>> time.get_clock_info("perf_counter")
namespace(implementation='clock_gettime(CLOCK_MONOTONIC)', monotonic=True, adjustable=False, resolution=1e-09)
  • time.time() and therefore time.time_ns() make no claim for being monotonic, meaning that it is possible that a later reading returns a lower number.
  • The resolution may vary, up to only being 16 milliseconds, as reported in this Stack Overflow post.

Note: This is platform dependent, in this case run in Python 3.11.5 on Linux 6.5.6-arch2-1.

I would suggest switching time.time_ns() with time.perf_counter_ns() as is usually done for reliable performance measurements.

There is a PR open fixing this at #5.

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

No branches or pull requests

1 participant