Speed up protocol checking
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
Use case : Each element in a list is run through `supports_protocol` to create a derivative list of objects where the derivative list only contains objects that support the interface/protocol of interest.
```
In [1]: from traits.adaptation.tests.interface_examples import UKPlug
In [3]: import time
In [4]: from traits.adaptation.tests.interface_examples import UKStandard
In [7]: from traits.adaptation.api import supports_protocol
In [8]: supports_protocol(UKPlug(), UKStandard)
Out[8]: True
In [9]: for num_plugs in [10, 10**2, 10**3, 10**4]:
...: plugs = [UKPlug() for _ in range(num_plugs)]
...: start = time.time()
...: supported_plugs = [plug for plug in plugs if supports_protocol(plug, UKStandard)]
...: print(time.time() - start)
...:
3.552436828613281e-05
0.00019216537475585938
0.0018210411071777344
0.02335357666015625
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.