The direction of the subtraction there is backwards from what I suspect was intended.
Perhaps more importantly, in the second code block (just after that):
a := monotime.Now()
someExpensiveOperation()
b := monotime.Now()
// b - a will *always* be greater than 0
That depends on your clock’s resolution – it might very well be zero if it’s coarse enough relative to the timed operation. “Never less than zero” would be a safer guarantee.
Another leap second, another slew of blog posts about them.
guess the posts will continue until folks get in the habit of using monotonic clocks for durations, and standard libraries support them more easily :)
The direction of the subtraction there is backwards from what I suspect was intended.
Perhaps more importantly, in the second code block (just after that):
That depends on your clock’s resolution – it might very well be zero if it’s coarse enough relative to the timed operation. “Never less than zero” would be a safer guarantee.