endail / hx711

Raspberry Pi HX711 C++ Library
MIT License
18 stars 10 forks source link

high_resolution_clock should be changed to steady_clock #70

Closed endail closed 1 year ago

endail commented 1 year ago

https://github.com/endail/hx711/blob/42d6305ab0aa8ad03e066a67a64228dc67bef4be/src/HX711.cpp#L310-L328

The high_resolution_clock is not implemented consistently across different standard library implementations, and its use should be avoided. It is often just an alias for std::chrono::steady_clock or std::chrono::system_clock, but which one it is depends on the library or configuration. When it is a system_clock, it is not monotonic (e.g., the time can go backwards). For example, for gcc's libstdc++ it is system_clock, for MSVC it is steady_clock, and for clang's libc++ it depends on configuration.

Generally one should just use std::chrono::steady_clock or std::chrono::system_clock directly instead of std::chrono::high_resolution_clock: use steady_clock for duration measurements, and system_clock for wall-clock time.

https://en.cppreference.com/w/cpp/chrono/high_resolution_clock