[pypy-dev] Copy of list

Vincent Legoll vincent.legoll at gmail.com
Mon Sep 28 18:47:11 CEST 2015


Hello,

is your code actually such a heavy list-copy-through-slicing user ?

This question is independent from pypy's eventual desire to speed
this python "idiom", though.

I myself was using it, but went to use list(), as that look more natural,
to my eyes, but that's a matter of taste anyways, I think...


On Mon, Sep 28, 2015 at 3:57 PM, Tuom Larsen <tuom.larsen at gmail.com> wrote:
> Dear PyPy developers!
>
> In CPython, a common idiom to copy a list is to use slice, as in:
>
>     copy = original[:]
>
> I noticed that under PyPy 2.6.0 it seems quite a bit slower than using
> `list` constructor:
>
>     from timeit import timeit
>     print timeit('b = a[:]', 'a = list(range(100))')    # 0.0732719898224
>     print timeit('b = list(a)', 'a = list(range(100))') # 0.00285792350769
>
> Please, could some comment on what is the preferred way to copy a list
> under PyPy? Should I try to avoid the "slice way"?
>
> Thanks!
> _______________________________________________
> pypy-dev mailing list
> pypy-dev at python.org
> https://mail.python.org/mailman/listinfo/pypy-dev



-- 
Vincent Legoll


More information about the pypy-dev mailing list