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

checking 'in' interval performance #32

Open
rotten opened this issue Jan 15, 2016 · 2 comments
Open

checking 'in' interval performance #32

rotten opened this issue Jan 15, 2016 · 2 comments

Comments

@rotten
Copy link

rotten commented Jan 15, 2016

I don't know if this is an issue, or if it is expected, but I was surprised at the performance difference between these two loops (2 orders of magnitude), so I thought I'd share:

import time
from intervals import IntInterval


myInterval = IntInterval('[2000,2500]')

start = time.time()
for x in range(0,1000):
   if 2222 in myInterval:  pass
   if x in myInterval: pass
end = time.time()
print end - start

start = time.time()
for x in range(0,1000):
   if 2222 >= myInterval.lower and 2222 <= myInterval.upper:  pass
   if x >= myInterval.lower and t <= myInterval.upper: pass
end = time.time()
print end - start
$  ./test_intervals_timing.py
0.0624339580536
0.000767946243286
@kvesteri
Copy link
Owner

Thanks for sharing this. I think most of the overhead comes from decorators and the fact that they coerce compared values to interval objects.

@edwardzhang0630
Copy link

edwardzhang0630 commented Mar 5, 2019

I have meet the same problem. When i use 'in' operation in a loop, it takes more than 20 mintes to finish the loop, I hope you can impove this performance problem.

Thanks for sharing this. I think most of the overhead comes from decorators and the fact that they coerce compared values to interval objects.

I have met the same problem. When i use 'in' operation in a loop, it takes more than 20 mintes to finish the loop, I hope you can impove this performance problem to makes it better to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants