time-machine icon indicating copy to clipboard operation
time-machine copied to clipboard

Also mock perf_counter

Open robsdedude opened this issue 2 years ago • 1 comments

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.

robsdedude avatar Nov 23 '23 13:11 robsdedude

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.

adamchainz avatar Nov 24 '23 11:11 adamchainz

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.

adamchainz avatar Aug 14 '24 22:08 adamchainz