gh-111482: Use Argument Clinic for clock_gettime()#111641
gh-111482: Use Argument Clinic for clock_gettime()#111641vstinner merged 3 commits intopython:mainfrom
Conversation
Use Argument Clinic for time.clock_gettime() and
time.clock_gettime_ns() functions.
Benchmark on time.clock_gettime_ns():
import time
import pyperf
runner = pyperf.Runner()
runner.timeit(
'clock_gettime_ns(CLOCK_MONOTONIC_COARSE)',
setup='import time; clock_gettime_ns=time.clock_gettime_ns; CLOCK_MONOTONIC_COARSE=6',
stmt='clock_gettime_ns(CLOCK_MONOTONIC_COARSE)')
Result on Linux with CPU isolation:
Mean +- std dev: [ref] 134 ns +- 1 ns -> [change] 55.7 ns +- 1.4 ns: 2.41x faster
|
cc @corona10 |
|
@vstinner |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Wow, it is impressive! I did not know there are still such low hanging fruits.
This PR consists of two parts.
clock_gettime()supported 64-bitclockid_ton AIX. This PR makesclock_gettime_ns()also supporting it. It looks rather like a bugfix, and I think it should be backported.clock_settime()andclock_settime_ns()also should support it.- Using Argument Clinic instead of
PyArg_ParseTuple().
Done. I did it, but then I made further changes. Apparently, I had to run it again. |
Honestly, I'm disappointed that PyArg_ParseTuple() is so slow :-( I suppose that creating a temporary tuple to pass positional arguments also has a cost. But yeah, it's a nice optimization.
We don't support AIX. I just tried to not regress. I don't plan to backport Argument Clinic code nor enhance time.clock_gettime_ns() on AIX in 3.12. |
|
Thanks for reviews. @serhiy-storchaka: If you are motivated to enhance AIX support in 3.12, please go ahead ;-) The two AIX buildbots are failing for many months... I'm not even sure why we still have AIX buildbots. |
Use Argument Clinic for time.clock_gettime() and
time.clock_gettime_ns() functions.
Benchmark on time.clock_gettime_ns():
import time
import pyperf
runner = pyperf.Runner()
runner.timeit(
'clock_gettime_ns(CLOCK_MONOTONIC_COARSE)',
setup='import time; clock_gettime_ns=time.clock_gettime_ns; CLOCK_MONOTONIC_COARSE=6',
stmt='clock_gettime_ns(CLOCK_MONOTONIC_COARSE)')
Result on Linux with CPU isolation:
Mean +- std dev: [ref] 134 ns +- 1 ns -> [change] 55.7 ns +- 1.4 ns: 2.41x faster
Use Argument Clinic for time.clock_gettime() and
time.clock_gettime_ns() functions.
Benchmark on time.clock_gettime_ns():
import time
import pyperf
runner = pyperf.Runner()
runner.timeit(
'clock_gettime_ns(CLOCK_MONOTONIC_COARSE)',
setup='import time; clock_gettime_ns=time.clock_gettime_ns; CLOCK_MONOTONIC_COARSE=6',
stmt='clock_gettime_ns(CLOCK_MONOTONIC_COARSE)')
Result on Linux with CPU isolation:
Mean +- std dev: [ref] 134 ns +- 1 ns -> [change] 55.7 ns +- 1.4 ns: 2.41x faster
Use Argument Clinic for time.clock_gettime() and
time.clock_gettime_ns() functions.
Benchmark on time.clock_gettime_ns():
import time
import pyperf
runner = pyperf.Runner()
runner.timeit(
'clock_gettime_ns(CLOCK_MONOTONIC_COARSE)',
setup='import time; clock_gettime_ns=time.clock_gettime_ns; CLOCK_MONOTONIC_COARSE=6',
stmt='clock_gettime_ns(CLOCK_MONOTONIC_COARSE)')
Result on Linux with CPU isolation:
Mean +- std dev: [ref] 134 ns +- 1 ns -> [change] 55.7 ns +- 1.4 ns: 2.41x faster
Use Argument Clinic for time.clock_gettime() and
time.clock_gettime_ns() functions.
Benchmark on time.clock_gettime_ns():
Result on Linux with CPU isolation:
Mean +- std dev: [ref] 134 ns +- 1 ns -> [change] 55.7 ns +- 1.4 ns: 2.41x faster