scandir slower than listdir
Torsten Bronger
bronger at physik.rwth-aachen.de
Thu Jul 20 01:33:03 EDT 2017
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"))
print("listdir:", time.time() - start)
start = time.time()
list(os.scandir("/home/bronger/.saves"))
print("scandir:", time.time() - start)
yields
listdir: 0.045470237731933594
scandir: 0.08043360710144043
However, scandir is supposed to be faster than listdir. Why do I
see this?
Tschö,
Torsten.
--
Torsten Bronger
More information about the Python-list
mailing list