Re: removing list comprehensions in Python 3.0
- From: "Devan L" <devlai@xxxxxxxxx>
- Date: 8 Jul 2005 22:44:49 -0700
>>> import timeit
>>> t1 = timeit.Timer('list(i for i in xrange(10))')
>>> t1.timeit()
27.267753024476576
>>> t2 = timeit.Timer('[i for i in xrange(10)]')
>>> t2.timeit()
15.050426800054197
>>> t3 = timeit.Timer('list(i for i in xrange(100))')
>>> t3.timeit()
117.61078097914682
>>> t4 = timeit.Timer('[i for i in xrange(100)]')
>>> t4.timeit()
83.502424470149151
Hrm, okay, so generators are generally faster for iteration, but not
for making lists(for small sequences), so list comprehensions stay.
.
- Follow-Ups:
- Re: removing list comprehensions in Python 3.0
- From: Steven Bethard
- Re: removing list comprehensions in Python 3.0
- References:
- removing list comprehensions in Python 3.0
- From: Steven Bethard
- Re: removing list comprehensions in Python 3.0
- From: Devan L
- Re: removing list comprehensions in Python 3.0
- From: Steven Bethard
- removing list comprehensions in Python 3.0
- Prev by Date: Re: removing list comprehensions in Python 3.0
- Next by Date: PPC floating equality vs. byte compilation
- Previous by thread: Re: removing list comprehensions in Python 3.0
- Next by thread: Re: removing list comprehensions in Python 3.0
- Index(es):
Relevant Pages
|