pyvisa / pyvisa-sim

A PyVISA backend that simulates a large part of the "Virtual Instrument Software Architecture" (VISA_)
https://pyvisa-sim.readthedocs.io/en/latest/
MIT License
69 stars 39 forks source link

Use the monotonic clock to measure time elapsed #85

Closed jtilahun closed 10 months ago

jtilahun commented 1 year ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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