Python3: on removing map, reduce, filter

Steven Bethard steven.bethard at gmail.com
Tue Jan 11 02:22:08 EST 2005


David M. Cooke wrote:
> Steven Bethard <steven.bethard at gmail.com> writes:
> 
>>Some timings to verify this:
>>
>>$ python -m timeit -s "def square(x): return x*x" "map(square, range(1000))"
>>1000 loops, best of 3: 693 usec per loop
>>
>>$ python -m timeit -s "[x*x for x in range(1000)]"
>>10000000 loops, best of 3: 0.0505 usec per loop
> 
> 
> Maybe you should compare apples with apples, instead of oranges :-)
> You're only running the list comprehension in the setup code...
> 
> $ python2.4 -m timeit -s "def square(x): return x*x" "map(square, range(1000))"
> 1000 loops, best of 3: 464 usec per loop
> $ python2.4 -m timeit "[x*x for x in range(1000)]"
> 1000 loops, best of 3: 216 usec per loop
> 
> So factor of 2, instead of 13700 ...

Heh heh.  Yeah, that'd be better.  Sorry about that!

Steve



More information about the Python-list mailing list