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 the monotonic clock to measure time elapsed #85

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

jtilahun
Copy link
Contributor

For measuring elapsed time, one should use a monotonic clock instead of the system clock because the system clock can go backwards in time, whereas a monotonic clock is guaranteed to be non-decreasing.

@dougthor42
Copy link
Contributor

Is there particular reason to use monotonic instead of perf_counter?

Also, would you rather use monotonic_ns (or perf_counter_ns) to avoid floating point errors?

@jtilahun
Copy link
Contributor Author

Is there particular reason to use monotonic instead of perf_counter?

Per PEP 418, monotonic is suitable for implementing a timeout in a program. perf_counter does exist as well, but perf_counter is intended for use in performance and benchmarking contexts.

Also, would you rather use monotonic_ns (or perf_counter_ns) to avoid floating point errors?

Are floating point errors a real concern here? If floating point errors are a true concern here, then it's possible to use the corresponding *_ns function to mitigate that concern.

@dougthor42
Copy link
Contributor

Per PEP 418 ...

Ah, thanks I didn't know that!

Are floating point errors a real concern here?

Unlikely. I just tend to use *_ns by default these days.

I'm not officially associated with pyvisa so feel free to ignore me 😁. For what it's worth (which is basically nil), this LGTM.

@MatthieuDartiailh
Copy link
Member

I was mostly worried about availability but this function is older than I though so no issue.

@MatthieuDartiailh MatthieuDartiailh merged commit f1e254c into pyvisa:main Oct 30, 2023
@jtilahun jtilahun deleted the monotonic branch October 30, 2023 15:07
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

Successfully merging this pull request may close these issues.

3 participants