View Single Post
Old Sep 23rd, 2005, 6:37 PM   #19
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Thanks Cerulean and hydroxide for the "replacement of lambda" suggestions.

Here is my code to time map() versus list comprehension:
# 85% of the time map() beats list comprehension by 5 - 10% on Windows XP  Python 2.4.1

import timeit

tt = timeit.Timer('map(str, [2, 3, 5, 1])')
te = (1000000 * tt.timeit(number=100000)/100000)
print "Function map(str, [2, 3, 5, 1]) uses %0.5f ms/pass" % te

tt = timeit.Timer('[str(x) for x in [2, 3, 5, 1]]')
te = (1000000 * tt.timeit(number=100000)/100000)
print "LC [str(x) for x in [2, 3, 5, 1]] uses %0.5f ms/pass" % te
Did the decorator syntax come from Java?
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote