This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JelleZijlstra
Recipients JelleZijlstra, domdfcoding, gvanrossum, joperez, kj, levkivskyi, lukasz.langa, miss-islington, uriyyo
Date 2021-07-20.15:09:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626793742.57.0.0770832303809.issue44353@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-07-20 15:09:02JelleZijlstrasetrecipients: + JelleZijlstra, gvanrossum, lukasz.langa, levkivskyi, miss-islington, uriyyo, joperez, domdfcoding, kj
2021-07-20 15:09:02JelleZijlstrasetmessageid: <1626793742.57.0.0770832303809.issue44353@roundup.psfhosted.org>
2021-07-20 15:09:02JelleZijlstralinkissue44353 messages
2021-07-20 15:09:02JelleZijlstracreate