Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
PEP 604 allowsisinstance on union types but it much slower compared to a tuple of types. This can be speed up with a fast path. Currently it is almost 4x slower, so there is room for improvement.
Benchmarks:
@kumaraditya303 ➜ /workspaces/cpython (fast-iter-str) $ ./python -m timeit "isinstance(1, (int, str))"5000000 loops, best of 5: 54.6 nsec per loop@kumaraditya303 ➜ /workspaces/cpython (fast-iter-str) $ ./python -m timeit "isinstance(1, int|str)"1000000 loops, best of 5: 202 nsec per loop