scandir slower than listdir
Terry Reedy
tjreedy at udel.edu
Thu Jul 20 02:32:30 EDT 2017
On 7/20/2017 1:33 AM, Torsten Bronger wrote:
> Hallöchen!
>
> With a 24,000 files directory on an SSD running Ubuntu,
>
> #!/usr/bin/python3
>
> import os, time
>
>
> start = time.time()
> list(os.listdir("/home/bronger/.saves"))
listdir returns a list of na
> print("listdir:", time.time() - start)
>
> start = time.time()
> list(os.scandir("/home/bronger/.saves"))
scandir returns an iterator of DirEntry objects which contain more
information than the mere name.
> print("scandir:", time.time() - start)
>
> yields
>
> listdir: 0.045470237731933594
> scandir: 0.08043360710144043
So you are comparing apples and apple tarts.
--
Terry Jan Reedy
More information about the Python-list
mailing list