On Tue, Mar 5, 2013 at 12:42 PM, Andrew Barnert <span dir="ltr"><<a href="mailto:abarnert@yahoo.com" target="_blank">abarnert@yahoo.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
So, that's a 1.8% speedup. While doing things right gives a 20% speedup:<br>
<br>
$ python3.3 -m timeit -n1000 "l=[]" "app = l.append" "for i in range(10000): app(i)"<br>
1000 loops, best of 3: 557 usec per loop<br>
$ python3.3 -m timeit -n1000 "l = [i for i in range(10000)]"<br>
1000 loops, best of 3: 447 usec per loop<br></blockquote><div><br></div><div>Yeah, I think it's pretty likely that any case where the proposed change would be applicable is probably going to be dominated by other factors more than by allocation overhead anyway..</div>
<div><br></div><div>The above does beg the question, though: Could we perhaps apply some of this thinking to list comprehensions, and speed them up even more by automatically taking hints from the inputs and preallocating the output list? (or do we already?)</div>
<div><br></div><div>Not sure how much work that would be, or whether it would be worth it.. just a random thought..</div><div><br></div><div>--Alex</div></div>