<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Aug 2, 2014 at 1:35 PM, David Wilson <span dir="ltr"><<a href="mailto:dw+python-dev@hmmz.org" target="_blank">dw+python-dev@hmmz.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">> Repeated list and str concatenation both have quadratic O(N**2)<br>
> performance, but people frequently build up strings with + <br></div></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
</div>join() isn't preferable in cases where it damages readability while<br>
simultaneously providing zero or negative performance benefit, such as<br>
when concatenating a few short strings, e.g. while adding a prefix to a<br>
filename.<br></blockquote><div><br></div><div>Good point -- I was trying to make the point about .join() vs + for strings in an intro python class last year, and made the mistake of having the students test the performance.</div>

<div><br></div><div>You need to concatenate a LOT of strings to see any difference at all --  I know that O() of algorithms is unavoidable, but between efficient python optimizations and a an apparently good memory allocator, it's really a practical non-issue.</div>

<div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Although it's true that join() is automatically the safer option, and<br>
especially when dealing with user supplied data, the net harm caused by<br>
teaching rote and ceremony seems far less desirable compared to fixing a<br>
trivial slowdown in a script, if that slowdown ever became apparent.<br></blockquote><div><br></div><div>and it rarely would. </div><div><br></div><div>Blocking sum( some_strings) because it _might_ have poor performance seems awfully pedantic.</div>

<div><br></div><div>As a long-time numpy user, I think sum(a_long_list_of_numbers) has pathetically bad performance, but I wouldn't block it!</div><div><br></div><div>-Chris</div><div><br></div><div><br></div></div>-- <br>

<br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br>

<br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a>
</div></div>