Jelle Zijlstra <[email protected]> added the comment:
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)
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue44353>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com