Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up protocol checking #455

Open
rahulporuri opened this issue Mar 12, 2019 · 0 comments
Open

Speed up protocol checking #455

rahulporuri opened this issue Mar 12, 2019 · 0 comments

Comments

@rahulporuri
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants