[pypy-issue] [issue967] itertools.imap significantly (order of magnitude) slower than map or gencomps

Xavier Morel tracker at bugs.pypy.org
Sun Dec 18 15:26:26 CET 2011


New submission from Xavier Morel <bugs.pypy.org at masklinn.net>:

> pypy-c -mtimeit -s 'l = range(20000)' -s 'f = lambda a: a + 1' 'list(f(v) for
v in l)'                           
100 loops, best of 3: 2.15 msec per loop
> pypy-c -mtimeit -s 'l = range(20000)' -s 'f = lambda a: a + 1' 'map(f, l)'   
                                   
1000 loops, best of 3: 1.58 msec per loop
> pypy-c -mtimeit -s 'from itertools import imap' -s 'l = range(20000)' -s 'f =
lambda a: a + 1' 'list(imap(f, l))'
100 loops, best of 3: 15.2 msec per loop

`itertools.imap` is 7 times slower than generator comprehensions and 10 times
slower than the `map` builtin in pypy.

By comparison, performance deviation is under 20% in CPython (2.6.1 here,
platform default)

> python -mtimeit -s 'l = range(20000)' -s 'f = lambda a: a + 1' 'list(f(v) for
v in l)'                       
100 loops, best of 3: 5.38 msec per loop
> python -mtimeit -s 'l = range(20000)' -s 'f = lambda a: a + 1' 'map(f, l)'   
                                   
100 loops, best of 3: 4.28 msec per loop
> python -mtimeit -s 'from itertools import imap' -s 'l = range(20000)' -s 'f =
lambda a: a + 1' 'list(imap(f, l))'
100 loops, best of 3: 4.04 msec per loop

(listcomps provide the same performances as `map` in pypy, which makes the
slowness of imap even stranger)

----------
messages: 3583
nosy: masklinn, pypy-issue
priority: performance bug
status: unread
title: itertools.imap significantly (order of magnitude) slower than map or gencomps

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue967>
________________________________________


More information about the pypy-issue mailing list