Showing content from http://mail.python.org/pipermail/python-dev/attachments/20160512/843b47d9/attachment.html below:
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 11 May 2016 at 22:51, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 05/11/2016 01:44 PM, Serhiy Storchaka wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
os.path<br>
'''''''<br>
<br>
The various path-manipulation functions of ``os.path`` [#os-path]_<br>
will be updated to accept path objects. For polymorphic functions that<br>
accept both bytes and strings, they will be updated to simply use<br>
code very much similar to<br>
``path.__fspath__() if hasattr(path, '__fspath__') else path``. This<br>
will allow for their pre-existing type-checking code to continue to<br>
function.<br>
</blockquote>
<br>
I afraid that this will hit a performance. Some os.path functions are<br>
used in tight loops, they are hard optimized, and adding support of path<br>
protocol can have visible negative effect.<br>
</blockquote>
<br></span>
Do you have an example of os.path functions being used in a tight loop?<br></blockquote><div><br></div><div>os.path.getmtime could be used in a tight loop, to sync directories with a lot of files for instance.</div><div><div><br></div><div>% python3 -m timeit -s "import os.path; p = 'out'" "hasattr(p, '__fspath__'), os.path.getmtime(p)"</div><div>100000 loops, best of 3: 2.67 usec per loop</div><div>% python3 -m timeit -s "import os.path; p = 'out'" "isinstance(p, (str, bytes)), os.path.getmtime(p)"</div><div>100000 loops, best of 3: 2.45 usec per loop</div><div>% python3 -m timeit -s "import os.path; p = 'out'" "os.path.getmtime(p)"Â </div><div>100000 loops, best of 3: 2.02 usec per loop</div></div><div><br></div><div>a 25% markup is a lot imo.</div><div><br></div><div>a isinstance check prior to the hasattr might be a way to mitigate this a bit (but it doesn't help much)</div><div>Granted, this example could be optimised by calling os.stat directly, which is not in os.path, but still, worth considering<br></div><div><br></div></div></div></div>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4