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

Improved logic for iterating over 'pairs.txt' #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sayandipdutta
Copy link

@sayandipdutta sayandipdutta commented Feb 1, 2022

closes #62
closes #63

Instead of loading the entire file into the memory, use the iterator
object natively provided by the file object returned by the open
function.

  • This saves memory.
  • Avoid __getitem__ call, improve performance.
  • More pythonic.

Instead of loading the entire file into the memory, use the iterator
object natively provided by the file object returned by the open
function.

- This saves memory.
- Avoid __getitem__ call, improve performance.
The inner loop used `range(len(imglist))`, this iterates over the entire
length twice. Using `enumerate` saves one complete iteration.

Furthermore, inside the inner loop `__getitem__` and `__setitem__` were
being called twice in each iteration. Reduces `__getitem__` calls to 0,
as it is already being taken care by for loop, and reduced `__setitem__`
to 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant