time-machine
time-machine copied to clipboard
Also mock perf_counter
Description
My application needs a monotonic clock and I much prefer time.perf_counter over time.monotonic for its greater precision. Therefore, I'd like to see time-machine also mock time.perf_counter and possibly also time.perf_counter_ns.
I understand that this constitutes a breaking change and that perf_counter is more likely to be used for benchmarking, so that might speak against it. Yet, I reckon mocking time while performing benchmarks is a rare use-case.
Sure, we could add mocking for perf_counter and perf_counter_ns. They fit in the same family as time.monotonic.
The time.monotonic patch seems to have broken asyncio tests: #387. I’m thinking of making it optional, and we could do the same for these functions.
Would you like to try making a PR? The monotonic PR may be an inspiration: #382.
Given the problems reported with monotonic mocking in #387, I’m considering rolling it back. I definitely don’t feel confident expanding to perf_counter now, since it may break more stuff, and it’s pretty niche anyway.