[Python-Dev] __file__ is not always an absolute path

Dan Villiom Podlaski Christiansen danchr at gmail.com
Wed Feb 17 09:47:17 CET 2010


On 7 Feb 2010, at 05:27, exarkun at twistedmatrix.com wrote:

> Do you know of a case where it's actually slow?  If not, how convincing should this argument really be?  Perhaps we can measure it on a few platforms before passing judgement.

On Mac OS X at least, system calls are notoriously slow. I think it has to do with Mach overhead, or something…

$ arch -arch ppc /usr/bin/python2.6 -m timeit -s 'def f(): pass' 'f()'
1000000 loops, best of 3: 0.476 usec per loop
$ arch -arch ppc /usr/bin/python2.6 -m timeit -s 'from os import getcwd' 'getcwd()'
10000 loops, best of 3: 21.9 usec per loop
$ arch -arch i386 /usr/bin/python2.6 -m timeit -s 'def f(): pass' 'f()'
1000000 loops, best of 3: 0.234 usec per loop
$ arch -arch i386 /usr/bin/python2.6 -m timeit -s 'from os import getcwd' 'getcwd()'
100000 loops, best of 3: 14.1 usec per loop
$ arch -arch x86_64 /usr/bin/python2.6 -m timeit -s 'def f(): pass' 'f()'
10000000 loops, best of 3: 0.182 usec per loop
$ arch -arch x86_64 /usr/bin/python2.6 -m timeit -s 'from os import getcwd' 'getcwd()'
100000 loops, best of 3: 11 usec per loop

For maximum reproducibility, I used the stock Python 2.6.1 included in Mac OS X 10.6.2. In other words ‘os.getcwd()’ is more than fifty times as slow as a regular function call when using Mac OS X.

--

Dan Villiom Podlaski Christiansen
danchr at gmail.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1943 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100217/d5bce968/attachment.bin>


More information about the Python-Dev mailing list