Hello
While reading the cProfile documentation’s Limitations section
, I came across the statement
The most obvious restriction is that the underlying “clock” is only ticking at a rate (typically) of about .001 seconds.
I’m trying to understand what this actually means.
From what I can see in the cpython’s source code, cProfile appears to use clock_gettime(CLOCK_MONOTONIC_RAW, ...) on Linux for time measurement. When I check the clock resolution with clock_getres on my system, it returns 1ns, so I’m confused why the documentation suggests a 1ms resolution (“about .001 seconds”) — that seems like a big mismatch in orders of magnitude.
Thank you very much! I understand the difference between the clock tick rate and reported resolution. On my environment, the clock rate is about every 100ns, which is much higher than 1ns. However, still, the orders of magnitude (10000x) gap between this measurement and the statement in the docs, which made me still confused
@barry-scott@elis.byberi
Thank you very much! I understand the difference between the clock tick rate and reported resolution. On my environment, the clock rate is about every 100ns, which is much higher than 1ns. However, still, the orders of magnitude (10000x) gap between this measurement and the statement in the docs (1ms), which made me still confused
It seems you are on a linux system. The default is 1000Hz for the clock tick.
You need to use a waiting sleep call to see the effect of the clock tick rate. Try asking for time after a sleep of 0.00001. I expect you to see reported time about 1ms apart not 0.1ms apart.
If you call a query in a tight loop you only get to see the sampling accuracy.
I thought that the 0.001s was true for Windows systems, but I have the same behavior with your script on my Windows 10 system, where it doesn’t get below 0.00006 s.
It’s not exactly outdated; it’s still relevant, but it’s unclear what the section is trying to explain. It may require in-depth knowledge of implementation details, especially since it discusses limitations.
Scheduler kernel timers are still observable, as I demonstrated in my previous post using multiprocessing (or threading).
The purpose of the Limitations section is to convey that certain constraints exist due to software or hardware limitations, without going too deep into technical detail.
It seems more like a note to one’s future self, though.