David M. Cooke wrote:
Steven Bethard <[EMAIL PROTECTED]> 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
--
http://mail.python.org/mailman/listinfo/python-list