[Python-Dev] file system path protocol PEP
Ethan Furman
ethan at stoneleaf.us
Wed May 11 20:40:22 EDT 2016
On 05/11/2016 05:13 PM, Arthur Darcet wrote:
> os.path.getmtime could be used in a tight loop, to sync directories with
> a lot of files for instance.
>
> % python3 -m timeit -s "import os.path; p = 'out'" "hasattr(p,
> '__fspath__'), os.path.getmtime(p)"
> 100000 loops, best of 3: 2.67 usec per loop
> % python3 -m timeit -s "import os.path; p = 'out'" "isinstance(p, (str,
> bytes)), os.path.getmtime(p)"
> 100000 loops, best of 3: 2.45 usec per loop
> % python3 -m timeit -s "import os.path; p = 'out'" "os.path.getmtime(p)"
> 100000 loops, best of 3: 2.02 usec per loop
>
> a 25% markup is a lot imo.
I don't think those results are very informative, since
os.path.getmtime() accepts both str and bytes, so it must already have
the str/bytes check.
--
~Ethan~
More information about the Python-Dev
mailing list