Message359081
Hm, here's what I measure in Python 3.8.1. (I don't use IPython or notebooks so this looks a little different.)
>>> timeit.timeit('Foo()', 'class Foo: pass')
0.37630256199999934
>>> timeit.timeit('Foo()', 'class Foo:\n def __new__(cls): return super().__new__(cls)')
1.5753196039999864
>>> timeit.timeit('Foo()', 'from typing import Generic, TypeVar\nT = TypeVar("T")\nclass Foo(Generic[T]): pass')
3.8748737150000068
From this I conclude that adding a minimal __new__() method is responsible for about 4x slowdown, and the functionality in typing.py for another factor 2.5.
While this isn't great I don't see an easy way to improve upon this without rewriting the entire typing module in C. (Some of this may or may not happen for PEP 604.)
PS. I just realized my Python binary was built with debug options, so absolute numbers will look different (better) for you -- but relative numbers will look the same, and I get essentially the same factors with 3.9.0a1+. |
|
Date |
User |
Action |
Args |
2019-12-31 01:31:15 | gvanrossum | set | recipients:
+ gvanrossum, levkivskyi, Ruslan Dautkhanov |
2019-12-31 01:31:15 | gvanrossum | set | messageid: <1577755875.89.0.318529664307.issue39168@roundup.psfhosted.org> |
2019-12-31 01:31:15 | gvanrossum | link | issue39168 messages |
2019-12-31 01:31:15 | gvanrossum | create | |
|