[Python-Dev] PEP 471 (scandir): Poll to choose the implementation (full C or C+Python) (original) (raw)

Serhiy Storchaka storchaka at gmail.com
Fri Feb 13 11:52:36 CET 2015


On 13.02.15 12:07, Victor Stinner wrote:

TL,DR: are you ok to add 800 lines of C code for os.scandir(), 4x faster than os.listdir() when the file type is checked?

You can try to make Python implementation faster if

  1. Don't set attributes to None in constructor.

  2. Implement scandir as:

def scandir(path): return map(partial(DirEntry, path), _scandir(path)).

  1. Or pass DirEntry to _scandir:

def scandir(path): yield from _scandir(path, DirEntry)



More information about the Python-Dev mailing list