Jelle Zijlstra <jelle.zijls...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue44353>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to