Message 363742 - Python tracker (original) (raw)

This is not how timeit works, you just measured the time taken by an empty loop, you can look at python3 -m timeit -h to get help how to call it. I think a correct invocation would be:

(venv) ➜ ~ python3 -m timeit -s 'from os import scandir' "list(scandir('/usr/local'))" 10000 loops, best of 5: 24.3 usec per loop (venv) ➜ ~ python3 -m timeit -s 'from os import listdir' "listdir('/usr/local')" 10000 loops, best of 5: 22.2 usec per loop

so it looks like scandir as a small overhead when accumulating all results and not using the extra info it returns.