A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-February/051792.html below:

[Python-Dev] PEP 309

[Python-Dev] PEP 309Raymond Hettinger python at rcn.com
Sun Feb 27 01:38:59 CET 2005
> I did a quick experiment:
> 
> >python -m timeit -s "from operator import itemgetter; l=range(8)"
> "itemgetter(1)(l)"
> 1000000 loops, best of 3: 0.548 usec per loop
> 
> >python -m timeit -s "l=range(8)" "(lambda x:x[1])(l)"
> 1000000 loops, best of 3: 0.597 usec per loop
> 
> That's far less of a difference than I expected from itemgetter! 

You've timed how long it takes to both construct and apply the retrieval
function.  The relevant part is only the application:

C:\pydev>python -m timeit -r9 -s "from operator import itemgetter;
s=range(8); f=itemgetter(1)" "f(s)"
1000000 loops, best of 9: 0.806 usec per loop

C:\pydev>python -m timeit -r9 -s "s=range(8); f=lambda x:x[1]" "f(s)"
100000 loops, best of 9: 1.18 usec per loop

So the savings is about 30% which is neither astronomical, nor
negligible.



Raymond

More information about the Python-Dev mailing list

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