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 Process.clock_gettime(Process::CLOCK_MONOTONIC) instead of Time? #4

Closed
srpouyet opened this issue Jan 24, 2019 · 4 comments · Fixed by #7
Closed

Use Process.clock_gettime(Process::CLOCK_MONOTONIC) instead of Time? #4

srpouyet opened this issue Jan 24, 2019 · 4 comments · Fixed by #7

Comments

@srpouyet
Copy link

Hi,

Thank you for open sourcing this!

I recently came across a post that I think might be useful for this gem: Elapsed time with Ruby, the right way. The author writes:

To recap: system clock is constantly floating and it doesn't move only forwards. If your calculation of elapsed time is based on it, you're very likely to run into calculation errors or even outages.

Remember: wall clock is for telling time, monotonic clock is for measuring time. ⏰

This is why you probably don't want to use Time but Process.clock_gettime(Process::CLOCK_MONOTONIC) to calculate the elapsed time.

Cheers!

@sbfaulkner
Copy link
Contributor

good point - this was accurate enough for our original need, but CLOCK_MONOTONIC would definitely be "more correct"

@sbfaulkner
Copy link
Contributor

we'll need to either get support for clock_gettime in Timecop, or mock our own equivalent for testing

@sbfaulkner
Copy link
Contributor

@srpouyet
Copy link
Author

Thanks @sbfaulkner ! 👍

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 a pull request may close this issue.

2 participants