News for hackers. Stuff that matters.
Re:Anti-Patterns in Python Programming by SEJeff on Wednesday July 09, 2014 @12:19PM (#8010449)
Map is not allegedly slower, it is demonstrably slower.

$ python -mtimeit -s'nums=range(10)' 'map(lambda i: i + 3, nums)' 1000000 loops, best of 3: 1.61 usec per loop

$ python -mtimeit -s'nums=range(10)' '[i + 3 for i in nums]' 1000000 loops, best of 3: 0.722 usec per loop

Function calls have overhead in python, list comprehensions are implemented knowing this fact and avoiding it so the heavy lifting ultimately happens in C code.

Re:Anti-Patterns in Python Programming by colcarroll on Wednesday July 09, 2014 @04:01PM (#8011914)
As you point out though, it depends on where the function is coming from:

$ python -mtimeit -s'nums=range(10)' '[str(i) for i in nums]' 100000 loops, best of 3: 2.57 usec per loop

$ python -mtimeit -s'nums=range(10)' 'map(str, nums)' 1000000 loops, best of 3: 1.88 usec per loop

$ python -mtimeit -s'nums=range(10)' 'import math' '[math.sqrt(i) for i in nums]' 100000 loops, best of 3: 3.25 usec per loop

$ python -mtimeit -s'nums=range(10)' 'import math' 'map(math.sqrt, nums)' 100000 loops, best of 3: 2.55 usec per loop

Re:Anti-Patterns in Python Programming by bkeroack on Wednesday July 09, 2014 @02:18PM (#8011332)
Fair enough. I said "allegedly" because I had never personally measured the performance difference.

Even though you could construe map as "half as fast" (or twice as slow) as the equivalent comprehension, I don't see a difference of ~1 usec making any difference in my code thus far. Good to know, though.

Re:Anti-Patterns in Python Programming by SEJeff on Wednesday July 09, 2014 @06:48PM (#8012641)
Yup, for very large calculations, or certain use cases, it can make much larger differences. It all depends on your use case.