Skip to content

Fix slow os.walk -> faster os.scandir#1

Open
vithursant wants to merge 2 commits into
dukebw:masterfrom
vithursant:vithu-dev
Open

Fix slow os.walk -> faster os.scandir#1
vithursant wants to merge 2 commits into
dukebw:masterfrom
vithursant:vithu-dev

Conversation

@vithursant

Copy link
Copy Markdown

os.walk is currently quite slow because it first lists the directory and then does a stat on each entry to see if it is a directory or a file.

switched to os.scandir() originally written by Ben Hoyt (see https://benhoyt.com/writings/scandir/).

Comment thread scripts/create_hdf5.py
num_ex = len(os.listdir(root))
print(root, num_ex)
for root in os.scandir(d):
if root.is_dir():

@dukebw dukebw Aug 9, 2019

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be assert root.is_dir()? Seems like if that's not true then (I meant fnames won't be set)*.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just seems odd that fnames is not set if this branch isn't hit.

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

Successfully merging this pull request may close these issues.

2 participants