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, uriyyo
Date 2021-07-19.21:16:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626729411.06.0.584775376483.issue44353@roundup.psfhosted.org>
In-reply-to
Content
This is what I got last year (copied from the typing issues):

In [83]: from typing import NewType

In [84]: nt = NewType("nt", int)

In [85]: class NewTypeClass:
    ...:     def __init__(self, name, supertype):
    ...:         self.name = name
    ...:         self.supertype = supertype
    ...:     def __call__(self, obj):
    ...:         return obj
    ...:     def __repr__(self):
    ...:         return f"<NewType: {self.name}>"
    ...:     

In [86]: ntc = NewTypeClass("ntc", int)

In [87]: ntc
Out[87]: <NewType: ntc>

In [88]: %timeit nt(3)
211 ns ± 2.27 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [89]: %timeit ntc(3)
253 ns ± 5.35 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)


Not sure what version of Python I used at the time. I just repeated it on 3.9.4 MacOS and got much faster time but a similar ~20% slowdown:

In [6]: %timeit nt(3)
112 ns ± 5.11 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

In [7]: %timeit ntc(3)
136 ns ± 2.36 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
History
Date User Action Args
2021-07-19 21:16:51JelleZijlstrasetrecipients: + JelleZijlstra, gvanrossum, levkivskyi, uriyyo, joperez, domdfcoding, kj
2021-07-19 21:16:51JelleZijlstrasetmessageid: <1626729411.06.0.584775376483.issue44353@roundup.psfhosted.org>
2021-07-19 21:16:51JelleZijlstralinkissue44353 messages
2021-07-19 21:16:50JelleZijlstracreate