Re: List Performance



Peter Otten wrote:
Ampedesign wrote:

If I happen to have a list that contains over 50,000 items, will the
size of the list severely impact the performance of appending to the
list?

No.

$ python -m timeit -n20000 -s"items = []" "items.append(42)"
20000 loops, best of 3: 0.554 usec per loop
$ python -m timeit -n20000 -s"items = [42]*10**6" "items.append(42)"
20000 loops, best of 3: 0.529 usec per loop

http://wiki.python.org/moin/TimeComplexity

Peter

Peter,

So its actually faster to append to a long list than an empty one? That certainly would not have been intuitively obvious now would it?

-Larry
.



Relevant Pages

  • Re: List Performance
    ... size of the list severely impact the performance of appending to the ... 20000 loops, best of 3: 0.554 usec per loop ... The difference is within the error margin. ...
    (comp.lang.python)
  • Re: List Performance
    ... size of the list severely impact the performance of appending to the ... 20000 loops, best of 3: 0.554 usec per loop ...
    (comp.lang.python)
  • Re: List Performance
    ... size of the list severely impact the performance of appending to the ... 20000 loops, best of 3: 0.554 usec per loop ...
    (comp.lang.python)
  • Re: reduce()--what is it good for? (was: Re: reduce() anomaly?)
    ... 1000 loops, best of 3: 290 usec per loop ... is about 3 times faster on a typical long seq ... > def longest: ...
    (comp.lang.python)
  • Re: in place input
    ... Python may do lots of allocations and deallocations for ... 1000000 loops, best of 3: 1.16 usec per loop ... creating a 220-character string by using the '*' operator takes just ...
    (comp.lang.python)