[issue44353] PEP 604 NewType
Jelle Zijlstra
report at bugs.python.org
Tue Jul 20 11:09:02 EDT 2021
Jelle Zijlstra <jelle.zijlstra at gmail.com> added the comment:
I found that replacing __call__ on the NewType class with an identity function written in C makes things faster instead:
In [54]: %timeit ntc2(1)
79 ns ± 0.37 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
In [55]: %timeit ntc(1)
126 ns ± 0.315 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
In [56]: %timeit nt(1)
103 ns ± 4.23 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
Here ntc2 has __call__ implemented in C, ntc is the previous class-based version and nt is the current function-based version.
So perhaps we could just stick a private `._idfunc` in some C-implemented module (functools? types?) and use it as the __call__ for our NewType class.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44353>
_______________________________________
More information about the Python-bugs-list
mailing list